View source
<?php
namespace Drupal\paragraphs_ee\Controller;
use Drupal\Core\Controller\ControllerBase;
class ParagraphsOffCanvasBrowser extends ControllerBase {
public function getTitle($entity_type, $bundle, $form_mode, $field_name) {
$title_default = $this
->t('Add Paragraph', [], [
'context' => 'Paragraphs Editor Enhancements',
]);
$form_display = $this
->entityTypeManager()
->getStorage('entity_form_display')
->load($entity_type . '.' . $bundle . '.' . $form_mode);
if (!$form_display) {
return $title_default;
}
$component = $form_display
->getComponent($field_name);
if (!$component || !isset($component['third_party_settings']['paragraphs_ee']['paragraphs_ee']['dialog_off_canvas']) || TRUE !== $component['third_party_settings']['paragraphs_ee']['paragraphs_ee']['dialog_off_canvas']) {
return $title_default;
}
return $this
->t('Add @widget_title', [
'@widget_title' => $component['settings']['title'],
], [
'context' => 'Paragraphs Editor Enhancements',
]);
}
public function content($entity_type, $bundle, $form_mode, $field_name) {
$build = [];
$form_display = $this
->entityTypeManager()
->getStorage('entity_form_display')
->load($entity_type . '.' . $bundle . '.' . $form_mode);
if (!$form_display) {
return $build;
}
$component = $form_display
->getComponent($field_name);
if (!$component || !isset($component['third_party_settings']['paragraphs_ee']['paragraphs_ee']['dialog_off_canvas']) || TRUE !== $component['third_party_settings']['paragraphs_ee']['paragraphs_ee']['dialog_off_canvas']) {
return $build;
}
$build['dialog'] = [
'#theme' => 'paragraphs_add_dialog__categorized',
'#add' => NULL,
'#attributes' => [
'role' => 'dialog',
'aria-modal' => 'false',
'aria-label' => $this
->t('Add @widget_title', [
'@widget_title' => $component['settings']['title'],
], [
'context' => 'Paragraphs Editor Enhancements',
]),
'data-field-name' => $field_name,
'data-widget-title' => $component['settings']['title'],
'data-widget-title-plural' => $component['settings']['title_plural'],
'class' => [
'paragraphs-add-dialog',
'paragraphs-add-dialog--categorized',
'js-hide',
],
],
'#groups' => [],
'#add_mode' => 'off_canvas',
];
$build['#attached']['library'][] = 'paragraphs_ee/paragraphs_ee.off_canvas';
return $build;
}
}