You are here

public function NodeTitle::settingsForm in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x src/Plugin/freelinking/NodeTitle.php \Drupal\freelinking\Plugin\freelinking\NodeTitle::settingsForm()

Plugin configuration form.

Parameters

array $form: The form element array for the filter plugin.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.

Return value

array The configuration form to attach to Freelinking settings form.

Overrides FreelinkingPluginBase::settingsForm

File

src/Plugin/freelinking/NodeTitle.php, line 95

Class

NodeTitle
Node Title freelinking plugin.

Namespace

Drupal\freelinking\Plugin\freelinking

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = [];
  $node_type_options = [];

  // Get the node type entities from storage from Entity Type Manager.
  // \Drupal\Core\Entity\EntityTypeBundleInfo::getAllBundleInfo() offers an
  // alter, but increased load times when not cached. It is debatable which
  // should be used in the long term.
  $node_types = $this->entityTypeManager
    ->getStorage('node_type')
    ->loadMultiple();
  foreach ($node_types as $entity) {
    $node_type_options[$entity
      ->id()] = $entity
      ->label();
  }
  $element['nodetypes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Only link to nodes belonging to the following content types:'),
    '#description' => $this
      ->t('Lookup by title to will be restricted to this content type or these content types.'),
    '#options' => $node_type_options,
    '#default_value' => isset($this->configuration['settings']['nodetypes']) ? $this->configuration['settings']['nodetypes'] : [],
  ];
  $failover_options = [
    '_none' => $this
      ->t('Do Nothing'),
    'showtext' => $this
      ->t('Show text (remove markup)'),
  ];
  if ($this->moduleHandler
    ->moduleExists('freelinking_prepopulate')) {
    $failover_options['freelinking_prepopulate'] = $this
      ->t('Add a link to create content when user has access');
  }
  if ($this->moduleHandler
    ->moduleExists('search')) {
    $failover_options['search'] = $this
      ->t('Add link to search content');
  }
  $failover_options['error'] = $this
    ->t('Insert an error message');
  $element['failover'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('If suitable content is not found'),
    '#description' => $this
      ->t('What should freelinking do when the page is not found?'),
    '#options' => $failover_options,
    '#default_value' => isset($this->configuration['settings']['failover']) ? $this->configuration['settings']['failover'] : '',
  ];
  return $element;
}