You are here

public function FlexiformEntityFormDisplay::getFormEnhancers in Flexiform 8

Get the enhancers for this form display.

Parameters

string $event: Optionally filter the enhancers by an applicable event.

Return value

\Drupal\flexiform\FormEnhancer\FormEnhancerInterface[] An array of form enhancers/

3 calls to FlexiformEntityFormDisplay::getFormEnhancers()
FlexiformEntityFormDisplay::getFormEnhancer in src/FlexiformEntityFormDisplay.php
Get a particular form enhancer.
FlexiformEntityFormDisplay::initFormEntityConfig in src/FlexiformEntityFormDisplay.php
FlexiformEntityFormDisplay::processForm in src/FlexiformEntityFormDisplay.php
Process callback: assigns weights and hides extra fields.

File

src/FlexiformEntityFormDisplay.php, line 510

Class

FlexiformEntityFormDisplay
Defines a class to extend EntityFormDisplays.

Namespace

Drupal\flexiform

Code

public function getFormEnhancers($event = NULL) {
  if (empty($this->formEnhancers)) {
    $enhancer_settings = $this
      ->getThirdPartySetting('flexiform', 'enhancer', []);
    $enhancer_definitions = \Drupal::service('plugin.manager.flexiform.form_enhancer')
      ->getDefinitions();
    foreach ($enhancer_definitions as $plugin_id => $definition) {
      $this->formEnhancers[$plugin_id] = \Drupal::service('plugin.manager.flexiform.form_enhancer')
        ->createInstance($plugin_id, isset($enhancer_settings[$plugin_id]) ? $enhancer_settings[$plugin_id] : [])
        ->setFormDisplay($this);
    }
  }
  if (is_null($event)) {
    return $this->formEnhancers;
  }
  $applicable_enhancer_names = [];
  foreach ($this->formEnhancers as $plugin_id => $enhancer) {
    if (($weight = $enhancer
      ->applies($event)) !== FALSE) {
      $applicable_enhancer_names[$plugin_id] = $weight;
    }
  }
  asort($applicable_enhancer_names);
  $applicable_enhancers = [];
  foreach ($applicable_enhancer_names as $plugin_id => $weight) {
    $applicable_enhancers[$plugin_id] = $this->formEnhancers[$plugin_id];
  }
  return $applicable_enhancers;
}