public function EntityFlagType::buildConfigurationForm in Flag 8.4
Provides a form for this action link plugin settings.
The form provided by this method is displayed by the FlagAddForm when creating or editing the Flag. Derived classes should override this.
Parameters
array $form: The form array.
FormStateInterface $form_state: The form state.
Return value
array The form array
Overrides FlagTypeBase::buildConfigurationForm
See also
1 call to EntityFlagType::buildConfigurationForm()
- UserFlagType::buildConfigurationForm in src/
Plugin/ Flag/ UserFlagType.php - Provides a form for this action link plugin settings.
1 method overrides EntityFlagType::buildConfigurationForm()
- UserFlagType::buildConfigurationForm in src/
Plugin/ Flag/ UserFlagType.php - Provides a form for this action link plugin settings.
File
- src/
Plugin/ Flag/ EntityFlagType.php, line 96
Class
- EntityFlagType
- Provides a flag type for all entity types.
Namespace
Drupal\flag\Plugin\FlagCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['display']['show_as_field'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display link as field'),
'#description' => $this
->t('Show the flag link as a field, which can be ordered among other entity elements in the "Manage display" settings for the entity type.'),
'#default_value' => $this
->showAsField(),
];
/*
if (empty($entity_info['fieldable'])) {
$form['display']['show_as_field']['#disabled'] = TRUE;
$form['display']['show_as_field']['#description'] = $this->t("This entity type is not fieldable.");
}
*/
$form['display']['show_on_form'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display checkbox on entity edit form'),
'#default_value' => $this
->showOnForm(),
'#weight' => 5,
];
// We use FieldAPI to put the flag checkbox on the entity form, so therefore
// require the entity to be fielable. Since this is a potential DX
// headscratcher for a developer wondering where this option has gone,
// we disable it and explain why.
/*
if (empty($entity_info['fieldable'])) {
$form['display']['show_on_form']['#disabled'] = TRUE;
$form['display']['show_on_form']['#description'] = $this->t('This is only possible on entities which are fieldable.');
}
*/
$form['display']['show_contextual_link'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display in contextual links'),
'#default_value' => $this
->showContextualLink(),
'#description' => $this
->t("Note that not all entity types support contextual links.\n <br/>\n <strong>Warning: </strong>Due to how contextual links are cached on frontend\n we have to set max-age as 0 for entity cache if\n user has access to contextual links and to this flag. This means that\n those users will get no cache hits for render elements rendering flaggable\n entities with contextual links."),
'#access' => $this->moduleHandler
->moduleExists('contextual'),
'#weight' => 10,
];
// Add checkboxes to show flag link on each entity view mode.
$options = [];
$defaults = [];
/* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_service */
$entity_display_service = \Drupal::service('entity_display.repository');
$view_modes = $entity_display_service
->getViewModes($this->entityType);
foreach ($view_modes as $name => $view_mode) {
$options[$name] = $this
->t('Display on @name view mode', [
'@name' => $view_mode['label'],
]);
if ($this
->showInLinks($name)) {
$defaults[$name] = $name;
}
}
$form['display']['show_in_links'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Display in entity links'),
'#description' => $this
->t('Show the flag link with the other links on the entity.'),
'#options' => $options,
'#default_value' => $defaults,
'#weight' => 15,
];
$form['access']['extra_permissions'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Expose additional permissions'),
'#options' => $this
->getExtraPermissionsOptions(),
'#default_value' => $this->configuration['extra_permissions'],
'#description' => $this
->t("Provides permissions with finer levels of access for this flag."),
];
return $form;
}