Skip to content
Snippets Groups Projects

Resolve #3426888 "Fix editing ui"

Merged Bálint Junkuncz requested to merge issue/custom_elements-3426888:3426888-fix-editing-ui into 3.x

Closes #3426888

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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)) {
  • 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'),
  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    • 78cc558a - Adds layout builder link functionality.

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 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());
    • seems wrong, we need an EntityCeDisplay, not an core entity-view-display.

      If that#s the purpose the method name and description is very misleading. it must pointt out what it is doing

    • 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 Junkuncz
    • your 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

    • Bálint Junkuncz changed this line in version 13 of the diff

      changed this line in version 13 of the diff

    • Please register or sign in to reply
  • 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()) {
  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 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(),
  • 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);
  • 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() {
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading