public function Eva::buildOptionsForm in EVA: Entity Views Attachment 8
Same name and namespace in other branches
- 8.2 src/Plugin/views/display/Eva.php \Drupal\eva\Plugin\views\display\Eva::buildOptionsForm()
Overrides \Drupal\views\Plugin\views\display\callbackPluginBase::buildOptionsForm().
Overrides DisplayPluginBase::buildOptionsForm
File
- src/
Plugin/ views/ display/ Eva.php, line 102
Class
- Eva
- The plugin that handles an EVA display in views.
Namespace
Drupal\eva\Plugin\views\displayCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$entity_info = \Drupal::entityManager()
->getDefinitions();
$entity_type = $this
->getOption('entity_type');
switch ($form_state
->get('section')) {
case 'entity_type':
foreach ($entity_info as $type => $info) {
// is this a content/front-facing entity?
if ($info instanceof \Drupal\Core\Entity\ContentEntityType) {
$entity_names[$type] = $info
->get('label');
}
}
$form['#title'] .= $this
->t('Entity type');
$form['entity_type'] = array(
'#type' => 'radios',
'#required' => TRUE,
'#validated' => TRUE,
'#title' => $this
->t('Attach this display to the following entity type'),
'#options' => $entity_names,
'#default_value' => $this
->getOption('entity_type'),
);
break;
case 'bundles':
$options = array();
foreach (\Drupal::entityManager()
->getBundleInfo($entity_type) as $bundle => $info) {
$options[$bundle] = $info['label'];
}
$form['#title'] .= $this
->t('Bundles');
$form['bundles'] = array(
'#type' => 'checkboxes',
'#title' => $this
->t('Attach this display to the following bundles. If no bundles are selected, the display will be attached to all.'),
'#options' => $options,
'#default_value' => $this
->getOption('bundles'),
);
break;
case 'arguments':
$form['#title'] .= $this
->t('Arguments');
$default = $this
->getOption('argument_mode');
$options = array(
'None' => $this
->t("No special handling"),
'id' => $this
->t("Use the ID of the entity the view is attached to"),
'token' => $this
->t("Use tokens from the entity the view is attached to"),
);
$form['argument_mode'] = array(
'#type' => 'radios',
'#title' => $this
->t("How should this display populate the view's arguments?"),
'#options' => $options,
'#default_value' => $default,
);
$form['token'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Token replacement'),
'#collapsible' => TRUE,
'#states' => array(
'visible' => array(
':input[name=argument_mode]' => array(
'value' => 'token',
),
),
),
);
$form['token']['default_argument'] = array(
'#title' => $this
->t('Arguments'),
'#type' => 'textfield',
'#default_value' => $this
->getOption('default_argument'),
'#description' => $this
->t('You may use token replacement to provide arguments based on the current entity. Separate arguments with "/".'),
);
break;
case 'show_title':
$form['#title'] .= $this
->t('Show title');
$form['show_title'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Show the title of the view above the attached view.'),
'#default_value' => $this
->getOption('show_title'),
);
break;
}
}