.../EntityReferenceEntityFormatter.php | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index e57cefd..e685317 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -9,6 +9,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Render\Markup; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -132,8 +133,13 @@ public function settingsForm(array $form, FormStateInterface $form_state) { $entity_type_id = $this->getFieldSetting('target_type'); $bundle_entity_type_id = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType(); $bundles = array_keys($this->getFieldSetting('handler_settings')['target_bundles']); + $description = [ + '#theme' => 'item_list', + '#context' => ['list_style' => 'comma-list'], + '#items' => [], + ]; if (count($bundles) === 1) { - $description = [ + $description['#items'][] = [ '#type' => 'link', '#title' => $this->t('Configure view modes'), '#url' => Url::fromRoute(sprintf('entity.entity_view_display.%s.default', $entity_type_id), [$bundle_entity_type_id => $bundles[0]]), @@ -148,11 +154,6 @@ public function settingsForm(array $form, FormStateInterface $form_state) { } else { $bundle_info = entity_get_bundles($entity_type_id); - $description = [ - '#theme' => 'item_list', - '#context' => ['list_style' => 'comma-list'], - '#items' => [], - ]; for ($i = 0; $i < count($bundles); $i++) { $description['#items'][] = [ '#type' => 'link', @@ -168,6 +169,19 @@ public function settingsForm(array $form, FormStateInterface $form_state) { ]; } } + $description['#items'][] = [ + '#type' => 'link', + '#title' => $this->t('Add new view mode'), + '#prefix' => Markup::create(t('or') . ' '), + '#url' => Url::fromRoute('entity.entity_view_mode.add_form', ['entity_type_id' => $entity_type_id]), + '#attributes' => [ + 'class' => ['use-ajax'], + 'data-dialog-type' => 'modal', + 'data-dialog-options' => json_encode([ + 'width' => 800, + ]), + ], + ]; $elements['view_mode'] = [ '#type' => 'select', '#options' => $this->entityDisplayRepository->getViewModeOptions($entity_type_id),