Builds a behavior perspective for each paragraph based on its type.
This method is responsible for building the behavior form for each Paragraph so the user can set special attributes and properties.
\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph.
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array The fields build array that the plugin creates.
Overrides ParagraphsBehaviorBase::buildBehaviorForm
public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
$config = $this
->getConfiguration();
$defined_layouts = $this->gridLayoutDiscovery
->getLayoutOptions();
if (empty($config['available_grid_layouts'])) {
$layout_options = $defined_layouts;
}
else {
$layout_options = array_intersect_key($defined_layouts, array_flip($config['available_grid_layouts']));
}
if ($layout_options) {
$form['#attached']['library'][] = 'paragraphs_collection/plugin_admin';
// Create a unique id for the wrapper.
$wrapper_id = Html::getUniqueId('layout-wrapper');
$form['layout_wrapper'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'paragraphs-plugin-inline-container',
'paragraphs-layout-select',
],
'id' => $wrapper_id,
],
];
$form['layout_wrapper']['layout'] = [
'#type' => 'select',
'#title' => $this
->t('Layout'),
// @todo Add the description about what happens if there are more items
// than slots.
// @todo Add a nice icon representing the layout.
'#empty_option' => $this
->t('- None -'),
'#options' => $layout_options,
'#default_value' => $paragraph
->getBehaviorSetting($this
->getPluginId(), 'layout'),
'#attributes' => [
'class' => [
'paragraphs-plugin-form-element',
],
],
];
}
else {
$form['message'] = [
'#type' => 'container',
'#markup' => $this
->t('No layouts available. See paragraphs_collection.api.php for more information on how to add them.'),
'#attributes' => [
'class' => [
'messages messages--warning',
],
],
];
}
return $form;
}