当前位置: 首页>>代码示例>>PHP>>正文


PHP AdminInterface::hasRequest方法代码示例

本文整理汇总了PHP中Sonata\AdminBundle\Admin\AdminInterface::hasRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP AdminInterface::hasRequest方法的具体用法?PHP AdminInterface::hasRequest怎么用?PHP AdminInterface::hasRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sonata\AdminBundle\Admin\AdminInterface的用法示例。


在下文中一共展示了AdminInterface::hasRequest方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateMenuUrl

 /**
  * {@inheritdoc}
  */
 public function generateMenuUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
 {
     // if the admin is a child we automatically append the parent's id
     if ($admin->isChild() && $admin->hasRequest() && $admin->getRequest()->attributes->has($admin->getParent()->getIdParameter())) {
         // twig template does not accept variable hash key ... so cannot use admin.idparameter ...
         // switch value
         if (isset($parameters['id'])) {
             $parameters[$admin->getIdParameter()] = $parameters['id'];
             unset($parameters['id']);
         }
         $parameters[$admin->getParent()->getIdParameter()] = $admin->getRequest()->attributes->get($admin->getParent()->getIdParameter());
     }
     // if the admin is linked to a parent FieldDescription (ie, embedded widget)
     if ($admin->hasParentFieldDescription()) {
         // merge link parameter if any provided by the parent field
         $parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array()));
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
         $parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode();
         $parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid();
     }
     if ($name == 'update' || substr($name, -7) == '|update') {
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
     }
     // allows to define persistent parameters
     if ($admin->hasRequest()) {
         $parameters = array_merge($admin->getPersistentParameters(), $parameters);
     }
     $code = $this->getCode($admin, $name);
     if (!array_key_exists($code, $this->caches)) {
         throw new \RuntimeException(sprintf('unable to find the route `%s`', $code));
     }
     return array('route' => $this->caches[$code], 'routeParameters' => $parameters, 'routeAbsolute' => $absolute);
 }
开发者ID:nfouka,项目名称:jobbet_sf2.5,代码行数:38,代码来源:DefaultRouteGenerator.php

示例2: alterNewInstance

 /**
  * Sanity check and default locale to request locale.
  *
  * {@inheritdoc}
  */
 public function alterNewInstance(AdminInterface $admin, $object)
 {
     if (!$object instanceof TranslatableInterface) {
         throw new \InvalidArgumentException('Expected TranslatableInterface, got ' . get_class($object));
     }
     if ($admin->hasRequest()) {
         $currentLocale = $admin->getRequest()->getLocale();
         if (in_array($currentLocale, $this->locales)) {
             $object->setLocale($currentLocale);
         }
     }
 }
开发者ID:frogriotcom,项目名称:CoreBundle,代码行数:17,代码来源:TranslatableExtension.php

示例3: preUpdate

 /**
  * {@inheritdoc}
  */
 public function preUpdate(AdminInterface $admin, $object)
 {
     if (!$admin->hasRequest() || !($data = $admin->getRequest()->get($admin->getUniqid()))) {
         return;
     }
     if (!isset($data[$this->fieldName])) {
         return;
     }
     $modelManager = $admin->getModelManager();
     if (!$modelManager instanceof LockInterface) {
         return;
     }
     $modelManager->lock($object, $data[$this->fieldName]);
 }
开发者ID:clavier-souris,项目名称:SonataAdminBundle,代码行数:17,代码来源:LockExtension.php

示例4: generateUrl

 /**
  * @throws \RuntimeException
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @param $name
  * @param array $parameter
  * @param bool $absolute
  * @return string
  */
 public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
 {
     if (!$admin->isChild()) {
         if (strpos($name, '.')) {
             $name = $admin->getCode() . '|' . $name;
         } else {
             $name = $admin->getCode() . '.' . $name;
         }
     } else {
         if ($admin->isChild()) {
             $name = $admin->getBaseCodeRoute() . '.' . $name;
             // twig template does not accept variable hash key ... so cannot use admin.idparameter ...
             // switch value
             if (isset($parameters['id'])) {
                 $parameters[$admin->getIdParameter()] = $parameters['id'];
                 unset($parameters['id']);
             }
             $parameters[$admin->getParent()->getIdParameter()] = $admin->getRequest()->get($admin->getParent()->getIdParameter());
         }
     }
     // if the admin is linked to a parent FieldDescription (ie, embedded widget)
     if ($admin->hasParentFieldDescription()) {
         // merge link parameter if any provided by the parent field
         $parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array()));
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
         $parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode();
         $parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid();
     }
     if ($name == 'update' || substr($name, -7) == '|update') {
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
     }
     // allows to define persistent parameters
     if ($admin->hasRequest()) {
         $parameters = array_merge($admin->getPersistentParameters(), $parameters);
     }
     $route = $admin->getRoute($name);
     if (!$route) {
         throw new \RuntimeException(sprintf('unable to find the route `%s`', $name));
     }
     return $this->router->generate($route->getDefault('_sonata_name'), $parameters, $absolute);
 }
开发者ID:natxet,项目名称:SonataAdminBundle,代码行数:51,代码来源:DefaultRouteGenerator.php

示例5: alterNewInstance

 /**
  * Set a default parent if defined in the request
  *
  * {@inheritDoc}
  */
 public function alterNewInstance(AdminInterface $admin, $object)
 {
     if (!$admin->hasRequest() || !($parentId = $admin->getRequest()->get('parent'))) {
         return;
     }
     $parent = $admin->getModelManager()->find(null, $parentId);
     if (!$parent) {
         return;
     }
     switch ($object) {
         case $object instanceof HierarchyInterface:
             $object->setParentDocument($parent);
             break;
         case $object instanceof ChildInterface:
             $object->setParentObject($parent);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Class %s is not supported', get_class($object)));
     }
 }
开发者ID:viral810,项目名称:ngSimpleCMS,代码行数:25,代码来源:ChildExtension.php

示例6: getCurrentAdminLocale

 /**
  * returns the locale of the current admin user
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @return mixed|string
  */
 public function getCurrentAdminLocale(\Sonata\AdminBundle\Admin\AdminInterface $admin)
 {
     $locale = '';
     if (!$admin->hasRequest()) {
         $admin->setRequest($this->getService('request'));
     }
     if ($subject = $admin->getSubject()) {
         return $this->getFieldValue($subject, 'locale');
     } elseif ($filter = $admin->getDatagrid()->getFilter('locale')) {
         /** @var \Sonata\AdminBundle\Filter\Filter $filter */
         $data = $filter->getValue();
         if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
             $locale = $this->getCurrentLocale();
         }
         $data['value'] = trim($data['value']);
         if (strlen($data['value']) > 0) {
             $locale = $data['value'];
         }
         if (!$locale && method_exists($admin, 'getDefaultLocale')) {
             $locale = $admin->getDefaultLocale();
         }
     }
     return $locale;
 }
开发者ID:rapemer,项目名称:init-cms-bundle,代码行数:30,代码来源:NetworkingHelperExtension.php


注:本文中的Sonata\AdminBundle\Admin\AdminInterface::hasRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。