public function PageExposure::configurationForm in Flexiform 8
The configuration form.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array The form with any additions.
Overrides ConfigurableFormEnhancerInterface::configurationForm
File
- src/
Plugin/ FormEnhancer/ PageExposure.php, line 61
Class
- PageExposure
- Plugin for exposing custom form modes on pages.
Namespace
Drupal\flexiform\Plugin\FormEnhancerCode
public function configurationForm(array $form, FormStateInterface $form_state) {
$target_entity_type_id = $this
->getFormDisplay()
->getTargetEntityTypeId();
$mode = $this
->getFormDisplay()
->getMode();
$target_entity_type = $this->entityTypeManager
->getDefinition($target_entity_type_id);
$form_mode = $this
->entityFormModeStorage()
->load("{$target_entity_type_id}.{$mode}");
$form_state
->set('entity_form_mode', $form_mode);
$form['description'] = [
'#type' => 'item',
'#markup' => $this
->t('Expose this form on a page at the path specified below, for more options consider using Page Manager.'),
];
$form['warning'] = [
'#type' => 'item',
'#markup' => $this
->t('<strong>Warning:</strong> These settings apply to all %entity_type %mode forms.', [
'%entity_type' => $target_entity_type
->getLabel(),
'%mode' => $form_mode
->label(),
]),
];
$settings = $form_mode
->getThirdPartySettings('flexiform');
$form['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Page Title'),
'#description' => $this
->t('The title of the page on which the form will appear.'),
'#default_value' => !empty($settings['exposure']['title']) ? $settings['exposure']['title'] : '',
];
$form['path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Path'),
'#description' => $this
->t('The path at which to expose the form. Use the following placeholders for form entity values:'),
'#default_value' => !empty($settings['exposure']['path']) ? $settings['exposure']['path'] : '',
];
$form['path']['#description'] .= '<ul>';
foreach ($this
->getFormDisplay()
->getFormEntityManager($form_state)
->getContexts() as $namespace => $context) {
/** @var \Drupal\flexiform\FormEntity\FormEntityContextInterface $context */
if ($namespace == '') {
$namespace = 'base_entity';
}
if ($context
->getFormEntity()
->getPluginId() == 'provided') {
$form['path']['#description'] .= '<li><strong>{' . $namespace . '}</strong> - ' . $context
->getContextDefinition()
->getLabel() . '</li>';
}
}
$form['path']['#description'] .= '</ul>';
return $form;
}