You are here

function varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_form_alter in Varbase Bootstrap Paragraphs 8.7

Same name and namespace in other branches
  1. 8.4 varbase_bootstrap_paragraphs.module \varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_form_alter()
  2. 8.5 varbase_bootstrap_paragraphs.module \varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_form_alter()
  3. 8.6 varbase_bootstrap_paragraphs.module \varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_form_alter()
  4. 9.0.x varbase_bootstrap_paragraphs.module \varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_form_alter()

Implements hook_field_widget_WIDGET_TYPE_form_alter().

Widget : Paragraphs Classic : entity_reference_paragraphs.

4 calls to varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_form_alter()
varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_previewer_form_alter in ./varbase_bootstrap_paragraphs.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().
varbase_bootstrap_paragraphs_field_widget_paragraphs_classic_asymmetric_form_alter in ./varbase_bootstrap_paragraphs.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().
varbase_bootstrap_paragraphs_field_widget_paragraphs_form_alter in ./varbase_bootstrap_paragraphs.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().
varbase_bootstrap_paragraphs_field_widget_paragraphs_previewer_form_alter in ./varbase_bootstrap_paragraphs.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().

File

./varbase_bootstrap_paragraphs.module, line 124
Varbase Bootstrap Paragraphs module file.

Code

function varbase_bootstrap_paragraphs_field_widget_entity_reference_paragraphs_form_alter(&$element, &$form_state, $context) {

  // Add the Varbase Bootstrap Paragraphs default admin styling.
  $element['subform']['#attached']['library'][] = 'varbase_bootstrap_paragraphs/vbp-default-admin';

  // If the paragraph type has got a background color field.
  if (isset($element['subform']['bp_background']) && isset($element['subform']['bp_background']['widget'])) {
    $configFactory = \Drupal::configFactory()
      ->getEditable('varbase_bootstrap_paragraphs.settings');
    $background_colors = $configFactory
      ->get('background_colors');
    $background_colors_options = [
      '_none' => t('N/A'),
    ];
    $lines = explode(PHP_EOL, $background_colors);
    foreach ($lines as $line) {
      $line = explode('|', $line);
      $background_colors_options[$line[0]] = $line[1];
    }

    // Updated the bp_background options with the list of vbp colors.
    $element['subform']['bp_background']['widget']['#options'] = $background_colors_options;

    // Get the default active theme for the site.
    $default_system_theme = \Drupal::configFactory()
      ->getEditable('system.theme');
    $default_active_theme_name = $default_system_theme
      ->get('default');
    $default_active_theme_libraries = \Drupal::service('library.discovery')
      ->getLibrariesByExtension($default_active_theme_name);

    // If the default active theme has got the vbp-colors library use it.
    if (isset($default_active_theme_libraries['vbp-colors'])) {
      $element['subform']['#attached']['library'][] = $default_active_theme_name . '/vbp-colors';
    }
    else {
      $element['subform']['#attached']['library'][] = 'varbase_bootstrap_paragraphs/vbp-colors';
    }
  }
}