/** * Constructs a BaseCommand object. * * @param string $data * The data to pass on to the client side. */ public function __construct(LayoutPageVariantInterface $page_variant, LayoutRegionInterface $layout_region) { $this->command = 'layoutRegionReload'; $data = PageLayout::getGroupedBlockArrays($page_variant); $region = array(); foreach ($data['regions'] as $nr => $region) { if ($region['id'] === $layout_region->id()) { $this->data = $region; break; } } }
public static function getRegionActions(LayoutPageVariantInterface $page_variant, LayoutRegionInterface $region) { $actions = array(); $page = $page_variant->getPage(); // @note: this is super-hacky; as we are looping the LayoutRegionPluginBag // in self::getGroupedBlockArrays we cannot iterate over it again without // resetting / affecting the outer loop :( so that's why we clone. $regions = clone $page_variant->getLayoutRegions(); $has_subregions = FALSE; foreach ($regions as $r) { if ($r->getParentRegionId() === $region->id()) { $has_subregions = TRUE; break; } } $has_blocks = ($blocks = $page_variant->getBlocksByRegion($region->id())) && sizeof($blocks); $is_configurable_region = is_subclass_of($region, 'Drupal\\page_layout\\Plugin\\LayoutRegion\\LayoutRegionPluginBase'); if (!$has_subregions) { $actions[] = new LayoutPageAction('add_block', t('Add block'), new Url('layout.page_variant_layout_blocks_select', array('page' => $page->id(), 'page_variant_id' => $page_variant->id(), 'layout_region_id' => $region->id()))); } if ($is_configurable_region) { $actions[] = new LayoutPageAction('configure_region', t('Configure region'), new Url('layout.layout_region_edit', array('page' => $page->id(), 'page_variant_id' => $page_variant->id(), 'layout_region_id' => $region->id()))); } if (!$has_blocks && $is_configurable_region && $region->canAddSubregions()) { $actions[] = new LayoutPageAction('add_subregion', t('Add subregion'), new Url('layout.page_variant_layout_regions_select', array('page' => $page->id(), 'page_variant_id' => $page_variant->id(), 'layout_region_id' => $region->id()))); } if ($is_configurable_region && $region->canBeDeleted()) { $actions[] = new LayoutPageAction('delete_region', t('Delete region'), new Url('layout.layout_region_delete', array('page' => $page->id(), 'page_variant_id' => $page_variant->id(), 'layout_region_id' => $region->id()))); } $action_array = array(); foreach ($actions as $action) { /** @var $action \Drupal\page_layout\LayoutPageAction */ $action_array[$action->id()] = $action->toArray(); } return $action_array; }
/** * Retrieves subregions of a given layout region. * * @param \Drupal\layout\Plugin\LayoutRegion\LayoutRegionInterface $parent_region * The layout region * @param \Drupal\layout\Plugin\Layout\LayoutBlockAndContextProviderInterface $provider * The block and context provider needed to build the layout region. * * @return \Drupal\layout\Plugin\LayoutRegion\LayoutRegionInterface[] * Instances of region plugins that are subregions. */ public function getSubRegions(LayoutRegionInterface $parent_region, LayoutBlockAndContextProviderInterface $provider) { $regions = $provider->getLayoutRegions(); $filtered = array(); foreach ($regions as $region) { if ($region->getParentRegionId() === $parent_region->id()) { $filtered[] = $region; } } return $filtered; }