/** * {@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()]); }
/** * 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; }