drowl_paragraphs_bs-1.x-dev/modules/drowl_paragraphs_bs_styles_ui/drowl_paragraphs_bs_styles_ui.module
modules/drowl_paragraphs_bs_styles_ui/drowl_paragraphs_bs_styles_ui.module
<?php
/**
* @file
* DROWL Paragraphs BS - Styles UI provides a hook for other modules to provide (a set of) CSS classes
* plus a preview image, a title and description per style.
*/
/**
* Returns an array of styles ui definitions.
*
* @return array
* The style definitions array in the defined format.
*/
function drowl_paragraphs_bs_styles_ui_definitions() {
$definitions = [];
// Get the icon path path prefix:
// $iconPathPrefix = base_path() . \Drupal::service('extension.list.module')->getPath('drowl_paragraphs_bs_styles_ui');
// The modules general definitions:
// $definitions['boxStyleBlack'] = [
// 'label' => t('Box Style: Black'),
// 'classesString' => 'box-style box-style--black',
// 'description' => t('Lorem ipsum dolar sit'),
// 'iconPath' => $iconPathPrefix . '/images/icons/boxStyleBlack.svg',
// ];
// Allow to alter the list
\Drupal::moduleHandler()->alter('drowl_paragraphs_bs_styles_ui_definitions', $definitions);
return $definitions;
}
/**
* Implements hook_field_widget_single_element_WIDGET_TYPE_form_alter.
*/
function drowl_paragraphs_bs_styles_ui_form_layout_paragraphs_component_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) : void {
// Provide definitions:
$form['#attached']['drupalSettings']['drowl_paragraphs_bs_styles_ui']['definitions'] = drowl_paragraphs_bs_styles_ui_definitions() ?: [];
// Attach admin library:
$form['#attached']['library'][] = 'drowl_paragraphs_bs_styles_ui/admin';
}
