public function LayoutParagraphsWidget::settingsSummary in Layout Paragraphs 1.0.x
Same name and namespace in other branches
- 2.0.x src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php \Drupal\layout_paragraphs\Plugin\Field\FieldWidget\LayoutParagraphsWidget::settingsSummary()
Returns a short summary for the current widget settings.
If an empty result is returned, a UI can still be provided to display a settings form in case the widget has configurable settings.
Return value
array A short summary of the widget settings.
Overrides WidgetBase::settingsSummary
File
- src/
Plugin/ Field/ FieldWidget/ LayoutParagraphsWidget.php, line 2262
Class
- LayoutParagraphsWidget
- Entity Reference with Layout field widget.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldWidgetCode
public function settingsSummary() {
$entity_type = $this
->getFieldSetting('target_type');
$target_bundles = array_keys($this
->getAllowedTypes());
$definition = $this->entityTypeManager
->getDefinition($entity_type);
$storage = $this->entityTypeManager
->getStorage($definition
->getBundleEntityType());
$has_layout = FALSE;
try {
if (!empty($target_bundles)) {
foreach ($target_bundles as $target_bundle) {
/** @var \Drupal\paragraphs\ParagraphsTypeInterface $type */
$type = $storage
->load($target_bundle);
if (count($this
->getAvailableLayoutsByType($type)) > 0) {
$has_layout = TRUE;
break;
}
}
}
} catch (\Exception $e) {
watchdog_exception('paragraphs layout widget, behaviour plugin', $e);
}
if (!$has_layout) {
$field_name = $this->fieldDefinition
->getLabel();
$message = $this
->t('To use layouts with the "@field_name" field, make sure you have enabled the "Paragraphs Layout" behavior for at least one target paragraph type.', [
'@field_name' => $field_name,
]);
$this
->messenger()
->addMessage($message, $this
->messenger()::TYPE_WARNING);
}
$summary = parent::settingsSummary();
$summary[] = $this
->t('Preview view mode: @preview_view_mode', [
'@preview_view_mode' => $this
->getSetting('preview_view_mode'),
]);
$summary[] = $this
->t('Maximum nesting depth: @max_depth', [
'@max_depth' => $this
->getSetting('nesting_depth'),
]);
if ($this
->getSetting('require_layouts')) {
$summary[] = $this
->t('Paragraphs <b>must be</b> added within layouts.');
}
else {
$summary[] = $this
->t('Layouts are optional.');
}
$summary[] = $this
->t('Maximum nesting depth: @max_depth', [
'@max_depth' => $this
->getSetting('nesting_depth'),
]);
return $summary;
}