/** * {@inheritdoc} */ public function getCancelUrl() { $entity_layout = $this->getEntityLayoutFromRouteMatch(); $target_entity_type = $entity_layout->getTargetEntityType(); $bundle_entity_type = $this->entityLayoutService->getTargetBundleEntityType($entity_layout); return Url::fromRoute("entity_layout.{$target_entity_type}.layout", [$bundle_entity_type => $this->entityLayout->getTargetBundle()]); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $content_entity = $this->getContentEntityFromRouteMatch(); if ($this->entityLayoutService->resetContentEntityLayout($this->contentEntity)) { drupal_set_message($this->t('The layout for @label has been reset.', ['@label' => $content_entity->label()])); } else { drupal_set_message($this->t('The layout for @label could not be reset. Please try again.', ['@label' => $content_entity->label()]), 'warning'); } $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $target_entity = $form_state->getValue('entity'); $target_bundle = $form_state->getValue('bundle', $target_entity); $this->entity->set('target_entity_type', $target_entity); $this->entity->set('target_bundle', $target_bundle); if ($target_entity !== $target_bundle) { drupal_set_message($this->t('A entity layout for the @entity entity and @bundle bundle has been created.', ['@entity' => $this->entityLayoutService->getTargetEntityLabel($this->entity), '@bundle' => $this->entityLayoutService->getTargetBundleLabel($this->entity)])); } else { drupal_set_message($this->t('A entity layout for the @entity entity has been created.', ['@entity' => $this->entityLayoutService->getTargetEntityLabel($this->entity)])); } $form_state->setRedirectUrl($this->entity->toUrl('collection')); }
/** * Get the operations for the entity row. * * @param EntityInterface $entity * * @return array */ public function getOperations(EntityInterface $entity) { /** @var EntityLayoutInterface $entity */ $bundle_entity_type = $this->entityLayoutService->getTargetBundleEntityType($entity); $target_entity_type = $entity->getTargetEntityType(); $operations = []; if ($entity->access('update')) { $operations['edit'] = array('title' => $this->t('Edit'), 'weight' => 10, 'url' => Url::fromRoute("entity_layout.{$target_entity_type}.layout", [$bundle_entity_type => $entity->getTargetBundle()])); } if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) { $operations['delete'] = array('title' => $this->t('Delete'), 'weight' => 100, 'url' => $entity->toUrl('delete-form')); } return $operations; }
/** * Build the render array for the block library. * * @param EntityLayoutInterface $entity_layout * The entity layout to show allowed blocks for. * @param ContentEntityInterface $content_entity * The content entity the block is being added to. * * @return array * The render array. */ protected function buildBlockLibrary(EntityLayoutInterface $entity_layout, ContentEntityInterface $content_entity = NULL) { $build['filter'] = ['#type' => 'search', '#title' => $this->t('Filter'), '#title_display' => 'invisible', '#size' => 30, '#placeholder' => $this->t('Filter by block name'), '#attributes' => ['class' => ['context-table-filter'], 'data-element' => '.block-add-table', 'title' => $this->t('Enter a part of the block name to filter by.')]]; $headers = [$this->t('Block'), $this->t('Category'), $this->t('Operations')]; $build['blocks'] = ['#type' => 'table', '#header' => $headers, '#rows' => [], '#empty' => $this->t('No blocks available for placement.'), '#attributes' => ['class' => ['block-add-table']]]; $blocks = $this->entityLayoutService->getSystemBlocks(); // Add each block definition to the table. foreach ($blocks as $block_id => $block) { if (!$entity_layout->blockIsAllowed($block_id)) { continue; } $bundle_entity_type = $this->entityLayoutService->getTargetBundleEntityType($entity_layout); // Use different routes depending on what kind of entity were adding // blocks for. if ($content_entity) { $entity_type_id = $content_entity->getEntityTypeId(); $block_add_url = Url::fromRoute("entity_layout.{$entity_type_id}.content.block.add", ['block_id' => $block_id, $entity_type_id => $content_entity->id()]); } else { $entity_type_id = $entity_layout->getTargetEntityType(); $block_add_url = Url::fromRoute("entity_layout.{$entity_type_id}.block.add", ['block_id' => $block_id, $bundle_entity_type => $entity_layout->getTargetBundle()]); } $links = ['add' => ['title' => $this->t('Place block'), 'url' => $block_add_url, 'attributes' => ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]]]; $build['blocks']['#rows'][] = ['title' => ['data' => ['#type' => 'inline_template', '#template' => '<div class="context-table-filter-text-source">{{ label }}</div>', '#context' => ['label' => $block['admin_label']]]], 'category' => ['data' => $block['category']], 'operations' => ['data' => ['#type' => 'operations', '#links' => $links]]]; } // @todo Create a filter behaviour for the table. //$build['#attached']['library'][] = 'context_ui/admin'; return $build; }
/** * Get an entity layout block content entity based on the route match * parameters. * * @return EntityLayoutBlockInterface */ protected function getEntityLayoutBlockFromRouteMatch() { if (!$this->entityLayoutBlock) { $parameters = $this->getRouteMatch()->getParameters()->all(); $this->entityLayoutBlock = $this->entityLayoutService->getContentBlockByUuid($parameters['block_id']); } return $this->entityLayoutBlock; }