/** * {@inheritDoc} */ public function getName(BlockInterface $block = null) { if (!$block || !$block->getReference()) { return 'Shared'; } return sprintf('%s (shared)', $this->getReferenceService($block)->getName($block->getReference())); }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { $gallery = $this->mediaManager->getRepository()->findByIds(json_decode($block->getValue())); if ($gallery) { $block->setGallery($gallery); } }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { $collection = $this->contentManager->getRepository()->createQueryBuilder('c')->where('c.id IN (:ids)')->setParameter('ids', json_decode($block->getValue()))->getQuery()->getResult(); if ($collection) { $block->setCollection($collection); } }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { $collection = $this->contentManager->getRepository()->findOrderedByIds(json_decode($block->getValue())); if ($collection) { $block->setCollection($collection); } }
public function getViewParameters(BlockInterface $block) { $properties = $block->getProperties(); $limit = isset($properties['limit']) ? $properties['limit'] : 5; $reviews = $this->reviewManager->getRepository()->createQueryBuilder('r')->orderBy('r.createdAt', 'DESC')->setMaxResults($limit)->getQuery()->getResult(); $parameters = parent::getViewParameters($block); $parameters['reviews'] = $reviews; return $parameters; }
/** * @param BlockInterface $block */ public function visit(BlockInterface $block) { if ($block instanceof BlockContainerInterface) { $iterator = $block->getChildren()->getIterator(); $iterator->uasort(function ($a, $b) { return $a->getSort() < $b->getSort() ? -1 : 1; }); $block->setChildren(new ArrayCollection(iterator_to_array($iterator))); } }
public function getViewParameters(BlockInterface $block) { $parameters = ['block_service' => $this, 'block' => $block]; if (!empty($block->getForm())) { /** @var PostInterface $post */ $post = $this->eavManager->initializeEntity($parameters['block']->getForm()->getSchema()); $this->prefillPost($post); $form = $this->formManager->createForm($block->getForm(), $post); $parameters['block']->formView = $form->createView(); } return $parameters; }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { $ids = json_decode($block->getValue()); if (empty($ids) || !count($ids)) { return; } $gallery = $this->mediaManager->getRepository()->findByIds($ids); uasort($gallery, function ($a, $b) use($ids) { return array_search($a->getId(), $ids) > array_search($b->getId(), $ids); }); if ($gallery) { $block->setGallery(new ArrayCollection($gallery)); } }
public function getViewParameters(BlockInterface $block) { $parameters = ['block_service' => $this, 'block' => $block]; $homePage = $this->contentManager->findOneBySlug('index'); $currentPage = $this->contentManager->findOneBySlug($block->getOwner()->getSlug()); //get current page slug to mark it as active when listing $parameters['currentPageSlug'] = $currentPage->getSlug(); $parameters['breadcrumbs'] = $currentPage->getBreadCrumbs(); // add homepage link as first breadcrumb if not exists in breadcrumbs if (!array_key_exists('index', $parameters['breadcrumbs'])) { $parameters['breadcrumbs'] = array_merge(['index' => $homePage->getTitle()], $parameters['breadcrumbs']); } return $parameters; }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { $properties = $block->getProperties(); $qb = $this->contentManager->getRepository()->createQueryBuilder('c'); if (isset($properties['order_by'])) { $direction = isset($properties['order_direction']) ? $properties['order_direction'] : 'ASC'; $qb->orderBy('c.' . $properties['order_by'], $direction); } $limit = isset($properties['limit']) ? $properties['limit'] : 10; $qb->setMaxResults($limit); $collection = $qb->getQuery()->getResult(); if ($collection) { $block->setCollection($collection); } }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { $levels = isset($block->getProperties()['levels']) ? $block->getProperties()['levels'] : 1; /** @var NavigationBlock $block */ if ($block->getValue() == NavigationBlock::CHOICE_CUSTOM && isset($block->getProperties()['content'])) { $ids = json_decode($block->getProperties()['content'], true); $collection = $this->contentManager->getRepository()->findOrderedByIds($ids); $block->setTree($collection); } elseif ($block->getValue() == NavigationBlock::CHOICE_TOP_LEVEL) { $collection = $this->contentManager->getRepository()->findByLevels($levels); $block->setTree($collection); } }
private function normalizeTabs(BlockInterface $block) { $properties = $block->getProperties(); if (isset($properties['tabs']) && count($properties['tabs'])) { if (isset($properties['tabs'][0]) && !is_array($properties['tabs'][0])) { $converted = array(); $sort = count($properties['tabs']); foreach ($properties['tabs'] as $key => $value) { $converted[] = ['label' => $value, 'key' => $key, 'sort' => $sort--]; } $properties['tabs'] = $converted; } $maxKey = 0; $maxSort = 0; array_walk($properties['tabs'], function ($tab) use(&$maxKey, &$maxSort) { if (isset($tab['key']) && $tab['key'] > $maxKey) { $maxKey = $tab['key']; } if (isset($tab['sort']) && $tab['sort'] > $maxSort) { $maxSort = $tab['sort']; } }); $maxKey++; $maxSort++; foreach ($properties['tabs'] as &$tab) { if (!isset($tab['key']) || $tab['key'] === null || $tab['key'] === "") { $tab['key'] = $maxKey++; } if (!isset($tab['sort']) || $tab['sort'] === null || $tab['sort'] === "") { $tab['sort'] = $maxSort++; } } uasort($properties['tabs'], function ($a, $b) { return $a['sort'] < $b['sort'] ? 1 : 0; }); $block->setProperties($properties); } return $block; }
public function getPlaceholders(BlockInterface $block = null) { $placeholders = []; for ($i = 0; $i < $block->getColumnCount(); $i++) { $placeholders[$i] = sprintf('Column %d', $i + 1); } return $placeholders; }
public function revertRecursiveFromNode(BlockInterface $block, $rootVersion) { if (!$block->getOwner()) { $this->revert($block, $rootVersion); return $block; } $owner = $block->getOwner(); $this->revert($owner, $rootVersion); $iterator = new \RecursiveIteratorIterator(new RecursiveBlockIterator($owner->getChildren()), \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $item) { if ($block->getId() == $item->getId()) { return $item; } } throw new \Exception(sprintf('Unable to revert with recursion. Could not find your node %s in the tree anymore', $block)); }
/** * @param BlockInterface $block * * @return null|string */ public function renderEsi(BlockInterface $block) { $reference = new ControllerReference('OpiferContentBundle:Frontend/Block:view', ['id' => $block->getId()], $this->getRequest()->query->all()); return $this->fragmentHandler->render($reference, 'esi'); }
/** * {@inheritDoc} */ public function getPlaceholders(BlockInterface $block = null) { $tabs = $block->getTabs(); return $tabs && count($tabs) ? $tabs : array(); }
/** * @param BlockInterface $block * * @return array */ public function getGutterStyles(BlockInterface $block) { $gutterStyles = array(); if ($block->getColumnCount()) { $properties = $block->getProperties(); if (isset($properties['gutters']) && count($properties['gutters']) > 0) { foreach ($properties['gutters'] as $screen => $cols) { foreach ($cols as $col => $span) { $gutterStyles[$col][] = "p-{$screen}-{$span}"; } } } } return $gutterStyles; }
/** * Gets the Block nodes siblings at a version. * * Retrieving siblings from the database could be simple if we did not need to take * the changesets into account, because then we would just get all blocks with the same * parent. However the changesets in BlockLogEntry probably store changed parents and * so they must be applied on the entire tree first before we can tell. * * @param BlockInterface $block * @param integer $version * * @return false|ArrayCollection */ public function getSiblings(BlockInterface $block, $version = false) { $owner = $block->getOwner(); $family = $this->findByOwner($owner, $version); $siblings = array(); foreach ($family as $member) { if ($member->getParent() && $member->getParent()->getId() == $block->getParent()->getId()) { array_push($siblings, $member); } } return $siblings; }
/** * Load the collection if any conditions are defined * * @param BlockInterface $block */ protected function loadCollection(BlockInterface $block) { $properties = $block->getProperties(); $conditions = isset($properties['conditions']) ? $properties['conditions'] : '[]'; $conditions = $this->expressionEngine->deserialize($conditions); if (empty($conditions)) { return; } $qb = $this->expressionEngine->toQueryBuilder($conditions, $this->contentManager->getClass()); if (isset($properties['order_by'])) { $direction = isset($properties['order_direction']) ? $properties['order_direction'] : 'ASC'; $qb->orderBy('a.' . $properties['order_by'], $direction); } $limit = isset($properties['limit']) ? $properties['limit'] : 10; $qb->setMaxResults($limit); $collection = $qb->getQuery()->getResult(); if ($collection) { $block->setCollection($collection); } }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { $properties = $block->getProperties(); $opts = array(); if (isset($properties['responseType']) && $properties['responseType'] == 'redirect') { $opts['action'] = $this->router->generate('opifer_mailing_list_subscribe_block', ['id' => $block->getId()]); } $this->form = $this->formFactory->create(SubscribeType::class, $this->subscription, $opts); $this->form->handleRequest($this->request); if ($this->form->isValid()) { foreach ($this->getMailingLists($block) as $list) { $subscription = $this->subscriptionManager->findOrCreate($list, $this->subscription->getEmail()); $this->subscriptionManager->save($subscription); } $this->subscribed = true; } }
/** * Returns if ESI is enabled on the reference service. * * {@inheritdoc} */ public function isEsiEnabled(BlockInterface $block) { if (!$block || !$block->getReference()) { return $this->esiEnabled; } return $this->getReferenceService($block)->isEsiEnabled($block->getReference()); }
public function allowShare(BlockInterface $block) { return !$block->isShared(); }
/** * @param BlockInterface $block */ public function load(BlockInterface $block) { /** @var NavigationBlock $block */ $block->setTree($this->GetTree($block->getValue())); }
/** * * @param BlockInterface $block * * @return array */ public function getBlockChildren(BlockInterface $block) { $this->loadBlocks(); $children = array(); $cacheKey = $this->getCacheKey(); foreach ($this->blockCache[$cacheKey] as $member) { if ($member->getParent() == null) { continue; } if ($member->getParent()->getId() == $block->getId()) { // direct child array_push($children, $member); } else { if ($member->getOwner() && $member->getParent()->getId() == $member->getOwner()->getId() && $block instanceof BlockOwnerInterface) { array_push($children, $member); } } } return $children; }
public function addToClipboard(BlockInterface $block) { $this->blockIds[] = $block->getId(); $this->session->set(self::SESSION_KEY, $this->blockIds); }