getSelectionGroups example


    return $element;
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $field = $form_state->getFormObject()->getEntity();

    // Get all selection plugins for this entity type.     $selection_plugins = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionGroups($this->getSetting('target_type'));
    $handlers_options = [];
    foreach (array_keys($selection_plugins) as $selection_group_id) {
      // We only display base plugins (e.g. 'default', 'views', ...) and not       // entity type specific plugins (e.g. 'default:node', 'default:user',       // ...).       if (array_key_exists($selection_group_id$selection_plugins[$selection_group_id])) {
        $handlers_options[$selection_group_id] = Html::escape($selection_plugins[$selection_group_id][$selection_group_id]['label']);
      }
      elseif (array_key_exists($selection_group_id . ':' . $this->getSetting('target_type')$selection_plugins[$selection_group_id])) {
        $selection_group_plugin = $selection_group_id . ':' . $this->getSetting('target_type');
        $handlers_options[$selection_group_plugin] = Html::escape($selection_plugins[$selection_group_id][$selection_group_plugin]['base_plugin_label']);
      }

    unset($options['handler']);

    return $this->createInstance($plugin_id$options);
  }

  /** * {@inheritdoc} */
  public function getPluginId($target_type$base_plugin_id) {
    // Get all available selection plugins for this entity type.     $selection_handler_groups = $this->getSelectionGroups($target_type);

    // Sort the selection plugins by weight and select the best match.     uasort($selection_handler_groups[$base_plugin_id]['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);
    end($selection_handler_groups[$base_plugin_id]);
    $plugin_id = key($selection_handler_groups[$base_plugin_id]);

    return $plugin_id;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.