/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $enabled_link = Link::fromTextAndUrl(t('enabled'), Url::fromRoute('system.modules_list'));
     $form['#attached']['library'][] = 'system/drupal.system';
     $form['exclude_node_title_search'] = ['#type' => 'checkbox', '#title' => $this->t('Remove node title from search pages'), '#description' => $this->t('Select if you wish to remove title from search pages. You need to have Search module @link.', ['@link' => $enabled_link]), '#default_value' => $this->excludeNodeTitleManager->isSearchExcluded(), '#disabled' => !\Drupal::moduleHandler()->moduleExists('search')];
     $form['content_type'] = ['#type' => 'fieldset', '#title' => $this->t('Exclude title by content types'), '#description' => $this->t('Define title excluding settings for each content type.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE];
     foreach ($this->bundleInfo->getBundleInfo('node') as $node_type => $node_type_info) {
         $form['#attached']['drupalSettings']['exclude_node_title']['content_types'][$node_type] = $node_type_info['label'];
         $form['content_type'][$node_type]['content_type_value'] = ['#type' => 'select', '#title' => $node_type_info['label'], '#default_value' => $this->excludeNodeTitleManager->getBundleExcludeMode($node_type), '#options' => ['none' => $this->t('None'), 'all' => $this->t('All nodes...'), 'user' => $this->t('User defined nodes...')]];
         $entity_view_modes = $this->entityDisplayRepository->getViewModes('node');
         $modes = [];
         foreach ($entity_view_modes as $view_mode_name => $view_mode_info) {
             $modes[$view_mode_name] = $view_mode_info['label'];
         }
         $modes += ['nodeform' => $this->t('Node form')];
         switch ($form['content_type'][$node_type]['content_type_value']['#default_value']) {
             case 'all':
                 $title = $this->t('Exclude title from all nodes in the following view modes:');
                 break;
             case 'user defined':
                 $title = $this->t('Exclude title from user defined nodes in the following view modes:');
                 break;
             default:
                 $title = $this->t('Exclude from:');
         }
         $form['content_type'][$node_type]['content_type_modes'] = ['#type' => 'checkboxes', '#title' => $title, '#default_value' => $this->excludeNodeTitleManager->getExcludedViewModes($node_type), '#options' => $modes, '#states' => ['invisible' => ['select[name="content_type[' . $node_type . '][content_type_value]"]' => ['value' => 'none']]]];
     }
     $form['#attached']['library'][] = 'exclude_node_title/drupal.exclude_node_title.admin';
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function settingsSummary()
 {
     $summary = array();
     $view_modes = $this->entityDisplayRepository->getViewModeOptions($this->getFieldSetting('target_type'));
     $view_mode = $this->getSetting('view_mode');
     $summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]) ? $view_modes[$view_mode] : $view_mode));
     return $summary;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $entity_type_id = $this->getFieldSetting('target_type');
     $states_prefix = 'fields[' . $this->fieldDefinition->getName() . '][settings_edit_form][settings]';
     $element = [];
     $element['form_mode'] = ['#type' => 'select', '#title' => $this->t('Form mode'), '#default_value' => $this->getSetting('form_mode'), '#options' => $this->entityDisplayRepository->getFormModeOptions($entity_type_id), '#required' => TRUE];
     $element['override_labels'] = ['#type' => 'checkbox', '#title' => $this->t('Override labels'), '#default_value' => $this->getSetting('override_labels')];
     $element['label_singular'] = ['#type' => 'textfield', '#title' => $this->t('Singular label'), '#default_value' => $this->getSetting('label_singular'), '#states' => ['visible' => [':input[name="' . $states_prefix . '[override_labels]"]' => ['checked' => TRUE]]]];
     $element['label_plural'] = ['#type' => 'textfield', '#title' => $this->t('Plural label'), '#default_value' => $this->getSetting('label_plural'), '#states' => ['visible' => [':input[name="' . $states_prefix . '[override_labels]"]' => ['checked' => TRUE]]]];
     return $element;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function clearCachedFieldDefinitions()
 {
     $this->baseFieldDefinitions = [];
     $this->fieldDefinitions = [];
     $this->fieldStorageDefinitions = [];
     $this->fieldMap = [];
     $this->fieldMapByFieldType = [];
     $this->entityDisplayRepository->clearDisplayModeInfo();
     $this->extraFields = [];
     Cache::invalidateTags(['entity_field_info']);
     // The typed data manager statically caches prototype objects with injected
     // definitions, clear those as well.
     $this->typedDataManager->clearCachedDefinitions();
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->container = $this->prophesize(ContainerInterface::class);
     \Drupal::setContainer($this->container->reveal());
     $this->typedDataManager = $this->prophesize(TypedDataManagerInterface::class);
     $this->typedDataManager->getDefinition('field_item:boolean')->willReturn(['class' => BooleanItem::class]);
     $this->container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
     $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
     $this->moduleHandler->alter('entity_base_field_info', Argument::type('array'), Argument::any())->willReturn(NULL);
     $this->moduleHandler->alter('entity_bundle_field_info', Argument::type('array'), Argument::any(), Argument::type('string'))->willReturn(NULL);
     $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
     $this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);
     $language = new Language(['id' => 'en']);
     $this->languageManager = $this->prophesize(LanguageManagerInterface::class);
     $this->languageManager->getCurrentLanguage()->willReturn($language);
     $this->languageManager->getLanguages()->willReturn(['en' => (object) ['id' => 'en']]);
     $this->keyValueFactory = $this->prophesize(KeyValueFactoryInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeRepository = $this->prophesize(EntityTypeRepositoryInterface::class);
     $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
     $this->entityDisplayRepository = $this->prophesize(EntityDisplayRepositoryInterface::class);
     $this->entityFieldManager = new TestEntityFieldManager($this->entityTypeManager->reveal(), $this->entityTypeBundleInfo->reveal(), $this->entityDisplayRepository->reveal(), $this->typedDataManager->reveal(), $this->languageManager->reveal(), $this->keyValueFactory->reveal(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal());
 }