You are here

public static function ParagraphsFeatures::registerFormWidgetFeatures in Paragraphs Features 8

Same name and namespace in other branches
  1. 2.x src/ParagraphsFeatures.php \Drupal\paragraphs_features\ParagraphsFeatures::registerFormWidgetFeatures()

Register features for paragraphs field widget.

Parameters

array $elements: Render array for the field widget.

\Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget $widget: Field widget object.

string $fieldWrapperId: Field Wrapper ID, usually provided by ::getWrapperId().

1 call to ParagraphsFeatures::registerFormWidgetFeatures()
paragraphs_features_field_widget_multivalue_form_alter in ./paragraphs_features.module
Implements hook_field_widget_multivalue_form_alter().

File

src/ParagraphsFeatures.php, line 57

Class

ParagraphsFeatures
Paragraphs features class.

Namespace

Drupal\paragraphs_features

Code

public static function registerFormWidgetFeatures(array &$elements, ParagraphsWidget $widget, $fieldWrapperId) {
  foreach (static::$availableFeatures as $feature) {
    if ($widget
      ->getThirdPartySetting('paragraphs_features', $feature)) {
      $elements['add_more']['#attached']['library'][] = 'paragraphs_features/drupal.paragraphs_features.' . $feature;
      $elements['add_more']['#attached']['drupalSettings']['paragraphs_features'][$feature][$fieldWrapperId] = TRUE;
      $elements['add_more']['#attached']['drupalSettings']['paragraphs_features'][$feature]['_path'] = drupal_get_path('module', 'paragraphs_features');
    }
  }
  $elements['add_more']['#attached']['library'][] = 'paragraphs_features/drupal.paragraphs_features.scroll_to_element';
  foreach (Element::children($elements['add_more']) as $button) {
    $elements['add_more'][$button]['#ajax']['callback'] = [
      static::class,
      'addMoreAjax',
    ];
  }

  // This feature is not part of of the foreach above, since it is not a
  // javascript feature, it is a direct modification of the form. If the
  // feature is not set, it defaults back to paragraphs behavior.
  if (!empty($elements['header_actions']['dropdown_actions']['dragdrop_mode'])) {
    $elements['header_actions']['dropdown_actions']['dragdrop_mode']['#access'] = (bool) $widget
      ->getThirdPartySetting('paragraphs_features', 'show_drag_and_drop', TRUE);
  }
}