Resolve #3426888 "Fix editing ui"
Closes #3426888
Merge request reports
Activity
159 176 } 160 177 } 161 178 $entity->setCustomElementName($form_values['custom_element_name']); 162 $entity->setStatus(TRUE); 179 if (array_key_exists('disable_default_ce_display', $form_values)) { changed this line in version 4 of the diff
90 90 '#required' => TRUE, 91 91 ]; 92 93 // Add enabling/disabling for default CE config. 94 if ($entity->getMode() === 'default') { 95 $id = $entity->getTargetEntityTypeId() . '.' . $entity->getTargetBundle() . '.' . $entity->getMode(); 96 $ce = $this->entityTypeManager->getStorage('entity_ce_display')->load($id); 97 98 if ($ce->get('status')) { 99 $this->messenger()->addWarning($this->t('Default CE display is disabled!')); 100 } 101 102 $form['disable_default_ce_display'] = [ 103 '#type' => 'checkbox', 104 '#title' => $this->t('Disable Default display'), 105 '#default_value' => (bool) $ce->get('status'), changed this line in version 4 of the diff
72 72 ); 73 73 } 74 74 75 /** 76 * Gets the current view display. 77 * 78 * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface 79 * The entity view display associated with the view mode. 80 */ 81 private function getDisplay() { 82 $entity = $this->getEntity(); 83 return $this->entityDisplayRepository->getViewDisplay($entity->getTargetEntityTypeId(), $entity->getTargetBundle(), $entity->getMode()); Hmm, yes it returns the core entity view display object currently. I've created this to be able to check layout builder' status on the current display and build the "link button" (Manage layout). EntityCeDisplay object doesn't store information about the builder (yet?) so to be able to build the link I need the view display object. eg.: /admin/structure/types/manage/article/display/default/layout
Maybe I'm wrong so I'd need feedback here.
Edited by Bálint Junkunczyour explanation makes sense. But that is not clear, or at least not clear enough, from the method name and comments. I'd suggest to inline load the core display into the method to check-for-enabled layout-builder. there should be no other use for the core-entity-displayy here, so no reason to add a confusing helper
changed this line in version 13 of the diff
157 * Checks layout_builder is enabled for the current view display. 158 * 159 * @return bool 160 * TRUE if it's enabled FALSE otherwise. 161 */ 162 protected function isLayoutBuilderEnabled() { 163 $display = $this->getDisplay(); 164 165 return $display->getThirdPartySetting('layout_builder', 'enabled'); 93 166 } 94 167 95 168 /** 96 169 * {@inheritdoc} 97 170 */ 98 171 protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) { 172 if ($this->isLayoutBuilderEnabled()) { Agree, I also had some fears about multiple checks. Will check and try to simplify.
Edited by Bálint JunkunczYes,
$form['#access'] = FALSE;
works but in this case all things are "gone" including the "Manage Layout" link. We could print it as a status message which means sth. like:$this->messenger()->addWarning($this->t($url));
so in this case we it's out of the $form render array and appears. Not sure to be honest what would be ideal. Suggestions are welcome. :)changed this line in version 14 of the diff
101 } 102 75 103 /** 76 104 * {@inheritdoc} 77 105 */ 78 106 public function form(array $form, FormStateInterface $form_state) { 79 107 $entity = $this->getEntity(); 108 109 if ($this->isLayoutBuilderEnabled()) { 110 if ($entity->getMode() === 'default') { 111 $form['manage_layout'] = [ 112 '#type' => 'link', 113 '#title' => $this->t('Manage layout'), 114 '#attributes' => ['class' => ['button']], 115 '#url' => Url::fromRoute("layout_builder.defaults." . $entity->getTargetEntityTypeId() . '.view', $this->getRouteParameters()), 116 '#access' => $this->isLayoutBuilderEnabled(), changed this line in version 14 of the diff
77 105 */ 78 106 public function form(array $form, FormStateInterface $form_state) { 79 107 $entity = $this->getEntity(); 108 109 if ($this->isLayoutBuilderEnabled()) { 110 if ($entity->getMode() === 'default') { 111 $form['manage_layout'] = [ 112 '#type' => 'link', 113 '#title' => $this->t('Manage layout'), 114 '#attributes' => ['class' => ['button']], 115 '#url' => Url::fromRoute("layout_builder.defaults." . $entity->getTargetEntityTypeId() . '.view', $this->getRouteParameters()), 116 '#access' => $this->isLayoutBuilderEnabled(), 117 ]; 118 } 119 120 $form = parent::form($form, $form_state); changed this line in version 14 of the diff
78 * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface 79 * The entity view display associated with the current CE display. 80 */ 81 protected function getEntityViewDisplay() { 82 $entity = $this->getEntity(); 83 return $this->entityDisplayRepository->getViewDisplay($entity->getTargetEntityTypeId(), $entity->getTargetBundle(), $entity->getMode()); 84 } 85 86 /** 87 * Provides the route parameters needed to generate a URL 88 * for the associated entity view display. 89 * 90 * @return mixed[] 91 * An associative array of parameter names and values. 92 */ 93 protected function getRouteParameters() { changed this line in version 24 of the diff