本文整理汇总了PHP中Sonata\BlockBundle\Block\BlockContextInterface::setSetting方法的典型用法代码示例。如果您正苦于以下问题:PHP BlockContextInterface::setSetting方法的具体用法?PHP BlockContextInterface::setSetting怎么用?PHP BlockContextInterface::setSetting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\BlockBundle\Block\BlockContextInterface
的用法示例。
在下文中一共展示了BlockContextInterface::setSetting方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$settings = $blockContext->getSettings();
$photos = $this->em->getRepository('AldorPortfolioBundle:Project')->getRecent($settings['max']);
$imageSize = 'medium';
if ($this->deviceDetector->isMobile()) {
$imageSize = 'small';
$blockContext->setSetting('extra_cache_key', 'mobile');
}
return $this->renderResponse($blockContext->getTemplate(), array('entities' => $photos, 'title' => $settings['title'], 'imageSize' => $imageSize), $response);
}
示例2: execute
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$settings = $blockContext->getSettings();
if ($settings['category']) {
$posts = $this->em->getRepository('AldorBlogBundle:Post')->getRecentPostsFromCategory($settings['category'], $settings['max']);
} else {
$posts = $this->em->getRepository('AldorBlogBundle:Post')->getRecentPosts($settings['max']);
}
$imagesSize = ['big', 'medium'];
if ($this->deviceDetector->isMobile()) {
$imagesSize = ['medium', 'medium'];
$blockContext->setSetting('extra_cache_key', 'mobile');
}
return $this->renderResponse($blockContext->getTemplate(), array('imagesSize' => $imagesSize, 'posts' => $posts, 'title' => $settings['title'], 'category' => $settings['category']), $response);
}
示例3: execute
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$settings = $blockContext->getSettings();
$gallery = $this->em->getRepository('AldorGalleryBundle:Gallery')->findOneBySlug($settings['gallery']);
$photos = array();
if ($gallery) {
$categories = $gallery->getCategories();
$photos = $this->em->getRepository('AldorGalleryBundle:Photo')->getRecentFromGallery($categories, $gallery->getId(), $settings['max']);
}
$imageSize = 'medium';
if ($this->deviceDetector->isMobile()) {
$imageSize = 'big200';
$blockContext->setSetting('extra_cache_key', 'mobile');
}
return $this->renderResponse($blockContext->getTemplate(), array('entities' => $photos, 'title' => $settings['title'] . ' z galerii ' . $settings['gallery'], 'active' => $settings['active'], 'gallery' => $gallery, 'imageSize' => $imageSize), $response);
}
示例4: getMenu
/**
* {@inheritdoc}
*/
protected function getMenu(BlockContextInterface $blockContext)
{
$blockContext->setSetting('include_homepage_link', false);
$menu = $this->getRootMenu($blockContext);
$page = $this->getCurrentPage();
if (!$page) {
return $menu;
}
$parents = $page->getParents();
foreach ($parents as $parent) {
if ($parent->isError()) {
continue;
}
$menu->addChild($parent->getName(), array('route' => 'page_slug', 'routeParameters' => array('path' => $parent->getUrl())));
}
if (!$page->isError()) {
$menu->addChild($page->getName(), array('route' => 'page_slug', 'routeParameters' => array('path' => $page->getUrl())));
}
return $menu;
}
示例5: setDefaultExtraCacheKeys
/**
* Adds context settings, to be able to rebuild a block context, to the
* extra_cache_keys
*
* @param BlockContextInterface $blockContext
* @param array $settings
*/
protected function setDefaultExtraCacheKeys(BlockContextInterface $blockContext, array $settings)
{
if (!$blockContext->getSetting('use_cache') || $blockContext->getSetting('ttl') <= 0) {
return;
}
$block = $blockContext->getBlock();
// type by block class
$class = ClassUtils::getClass($block);
$cacheServiceId = isset($this->cacheBlocks['by_class'][$class]) ? $this->cacheBlocks['by_class'][$class] : false;
// type by block service
if (!$cacheServiceId) {
$cacheServiceId = isset($this->cacheBlocks['by_type'][$block->getType()]) ? $this->cacheBlocks['by_type'][$block->getType()] : false;
}
if (!$cacheServiceId) {
// no context cache needed
return;
}
// do not add cache settings to extra_cache_keys
unset($settings['use_cache'], $settings['extra_cache_keys'], $settings['ttl']);
$extraCacheKeys = $blockContext->getSetting('extra_cache_keys');
// add context settings to extra_cache_keys
if (!isset($extraCacheKeys[self::CACHE_KEY])) {
$extraCacheKeys[self::CACHE_KEY] = $settings;
$blockContext->setSetting('extra_cache_keys', $extraCacheKeys);
}
}
示例6: execute
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
// make sure we have a valid format
$media = $blockContext->getBlock()->getSetting('mediaId');
if ($media instanceof MediaInterface) {
$choices = $this->getFormatChoices($media);
if (!array_key_exists($blockContext->getSetting('format'), $choices)) {
$blockContext->setSetting('format', key($choices));
}
}
return $this->renderResponse($blockContext->getTemplate(), array('media' => $blockContext->getSetting('mediaId'), 'block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings()), $response);
}
示例7: execute
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$settings = $blockContext->getSettings();
$repository = $this->em->getRepository('KinkinwebLhvbBundle:Bureau');
$data = $repository->findAll();
// make sure we have a valid format
$media = $blockContext->getBlock()->getSetting('mediaId');
if ($media instanceof MediaInterface) {
$choices = $this->getFormatChoices($media);
if (!array_key_exists($blockContext->getSetting('format'), $choices)) {
$blockContext->setSetting('format', key($choices));
}
}
if (!empty($data)) {
$bureau = $data[0];
} else {
$bureau = null;
}
return $this->renderResponse($blockContext->getTemplate(), array('bureau' => $bureau, 'media' => $blockContext->getSetting('mediaId'), 'block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings()), $response);
}