作者:symfony-cm
项目:routing-bundl
/**
* @throws InvalidConfigurationException
*/
public function configureTabMenu(AdminInterface $admin, MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!($subject = $admin->getSubject())) {
return;
}
if (!$subject instanceof RouteReferrersReadInterface && !$subject instanceof Route) {
throw new InvalidConfigurationException(sprintf('%s can only be used on subjects which implement Symfony\\Cmf\\Component\\Routing\\RouteReferrersReadInterface or Symfony\\Component\\Routing\\Route.', __CLASS__));
}
if ($subject instanceof PrefixInterface && !is_string($subject->getId())) {
// we have an unpersisted dynamic route
return;
}
$defaults = array();
if ($subject instanceof TranslatableInterface) {
if ($locale = $subject->getLocale()) {
$defaults['_locale'] = $locale;
}
}
try {
$uri = $this->router->generate($subject, $defaults);
} catch (RoutingExceptionInterface $e) {
// we have no valid route
return;
}
$menu->addChild($this->translator->trans('admin.menu_frontend_link_caption', array(), 'CmfRoutingBundle'), array('uri' => $uri, 'attributes' => array('class' => 'sonata-admin-menu-item', 'role' => 'menuitem'), 'linkAttributes' => array('class' => 'sonata-admin-frontend-link', 'role' => 'button', 'target' => '_blank', 'title' => $this->translator->trans('admin.menu_frontend_link_title', array(), 'CmfRoutingBundle'))));
}
作者:OskarStar
项目:SonataTimelineBundl
public function setUp()
{
$this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface', array('hasRoute', 'isGranted', 'generateObjectUrl', 'generateUrl', 'toString'));
$this->pool = $this->getMock('Sonata\\AdminBundle\\Admin\\Pool', array('getAdminByClass'));
$this->pool->expects($this->any())->method('getAdminByClass')->with($this->equalTo('Acme\\DemoBundle\\Model\\Demo'))->will($this->returnValue($this->admin));
$this->twigExtension = new SonataTimelineExtension($this->pool);
}
作者:natxe
项目:SonataAdminBundl
/**
* Configure the object ACL for the passed object identities
*
* @param OutputInterface $output
* @param AdminInterface $admin
* @param array $oids an array of ObjectIdentityInterface implementations
* @param UserSecurityIdentity $securityIdentity
*
* @throws \Exception
*
* @return array [countAdded, countUpdated]
*/
public function configureAcls(OutputInterface $output, AdminInterface $admin, array $oids, UserSecurityIdentity $securityIdentity = null)
{
$countAdded = 0;
$countUpdated = 0;
$securityHandler = $admin->getSecurityHandler();
if (!$securityHandler instanceof AclSecurityHandlerInterface) {
$output->writeln(sprintf('Admin `%s` is not configured to use ACL : <info>ignoring</info>', $admin->getCode()));
return array(0, 0);
}
$acls = $securityHandler->findObjectAcls($oids);
foreach ($oids as $oid) {
if ($acls->contains($oid)) {
$acl = $acls->offsetGet($oid);
$countUpdated++;
} else {
$acl = $securityHandler->createAcl($oid);
$countAdded++;
}
if (!is_null($securityIdentity)) {
// add object owner
$securityHandler->addObjectOwner($acl, $securityIdentity);
}
$securityHandler->addObjectClassAces($acl, $securityHandler->buildSecurityInformation($admin));
try {
$securityHandler->updateAcl($acl);
} catch (\Exception $e) {
$output->writeln(sprintf('Error saving ObjectIdentity (%s, %s) ACL : %s <info>ignoring</info>', $oid->getIdentifier(), $oid->getType(), $e->getMessage()));
}
}
return array($countAdded, $countUpdated);
}
作者:hunter127
项目:IphpTreeBundl
/**
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param array $values
* @return \Sonata\AdminBundle\Datagrid\DatagridInterface
*/
public function getBaseDatagrid(AdminInterface $admin, array $values = array())
{
$pager = new Pager();
$pager->setCountColumn($admin->getModelManager()->getIdentifierFieldNames($admin->getClass()));
$formBuilder = $this->formFactory->createNamedBuilder('form', 'filter', array(), array('csrf_protection' => false));
return new Datagrid($admin->createQuery(), $admin->getList(), $pager, $formBuilder, $values);
}
作者:endroi
项目:EndroidBehaviorBundl
/**
* {@inheritdoc}
*/
public function alterNewInstance(AdminInterface $admin, $object)
{
if ($object->getParent() == null) {
$reflectionClass = $admin->getClass();
$parent = $this->container->get('doctrine')->getRepository($reflectionClass)->findOneById($this->getRequest()->query->get('parent'));
$object->setParent($parent);
}
}
作者:helme
项目:SonataAdminBundl
/**
* {@inheritDoc}
*/
public function buildSecurityInformation(AdminInterface $admin)
{
$baseRole = 'ROLE_' . str_replace('.', '_', strtoupper($admin->getCode())) . '_%s';
$results = array();
foreach ($admin->getSecurityInformation() as $name => $permissions) {
$results[sprintf($baseRole, $name)] = $permissions;
}
return $results;
}
作者:ynloultratec
项目:framewor
/**
* {@inheritdoc}
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setTemplate('YnloAdminBundle::CRUD/list_enum.html.twig');
/** @var ModelManager $modelManager */
$modelManager = $admin->getModelManager();
if (null === $fieldDescription->getOption('enum_type') && $modelManager->hasMetadata($admin->getClass())) {
$mapping = $modelManager->getMetadata($admin->getClass())->getFieldMapping($fieldDescription->getName());
$fieldDescription->setOption('enum_type', $mapping['type']);
}
}
作者:kaza
项目:foru
/**
* @param FormMapper $formMapper
* @param AdminInterface $admin
* @param string $formField
* @param string $field
* @param array $fieldOptions
* @param array $adminOptions
*
* @return FormBuilder
*/
protected final function getFormAdminType(FormMapper $formMapper, AdminInterface $admin, $formField, $field, $fieldOptions = array(), $adminOptions = array())
{
$adminOptions = array_merge(array('edit' => 'list', 'translation_domain' => 'SonataClassificationBundle'), $adminOptions);
$fieldDescription = $admin->getModelManager()->getNewFieldDescriptionInstance($admin->getClass(), $field, $adminOptions);
$fieldDescription->setAssociationAdmin($admin);
$fieldDescription->setAdmin($formMapper->getAdmin());
$fieldDescription->setAssociationMapping(array('fieldName' => $field, 'type' => ClassMetadataInfo::MANY_TO_ONE));
$fieldOptions = array_merge(array('sonata_field_description' => $fieldDescription, 'class' => $admin->getClass(), 'model_manager' => $admin->getModelManager(), 'required' => false), $fieldOptions);
return $formMapper->create($formField, 'sonata_type_model_list', $fieldOptions);
}
作者:saberyouni
项目:Sonata-Projec
/**
* {@inheritdoc}
*/
public function buildField($type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
} else {
$fieldDescription->setType($type);
}
$this->fixFieldDescription($admin, $fieldDescription);
}
作者:frogriotco
项目:CoreBundl
/**
* 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);
}
}
}
作者:jorri
项目:SonataTranslationBundl
/**
* Return current translatable locale
* ie: the locale used to load object translations != current request locale.
*
* @return string
*/
public function getTranslatableLocale(AdminInterface $admin)
{
if ($this->translatableLocale == null) {
if ($admin->getRequest()) {
$this->translatableLocale = $admin->getRequest()->get(self::TRANSLATABLE_LOCALE_PARAMETER);
}
if ($this->translatableLocale == null) {
$this->translatableLocale = $this->getDefaultTranslationLocale($admin);
}
}
return $this->translatableLocale;
}
作者:nzzde
项目:SonataDoctrinePhpcrAdminBundl
/**
* Adds a field to the Field description collection and sets its type.
* If not type provided, will try to guess it.
*
* @param \Sonata\AdminBundle\Admin\FieldDescriptionCollection $list
* @param string|null $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @return FieldDescriptionCollection
*/
public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName());
$fieldDescription->setType($guessType->getType());
} else {
$fieldDescription->setType($type);
}
$this->fixFieldDescription($admin, $fieldDescription);
$admin->addListFieldDescription($fieldDescription->getName(), $fieldDescription);
return $list->add($fieldDescription);
}
作者:nzzde
项目:SonataDoctrinePhpcrAdminBundl
/**
* RouteBuilder that allowes slashes in the ids.
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Route\RouteCollection $collection
*/
function build(AdminInterface $admin, RouteCollection $collection)
{
$collection->add('list');
$collection->add('create');
$collection->add('batch');
$collection->add('edit', $admin->getRouterIdParameter() . '/edit', array(), array('id' => '.+'));
$collection->add('delete', $admin->getRouterIdParameter() . '/delete', array(), array('id' => '.+'));
$collection->add('show', $admin->getRouterIdParameter(), array(), array('id' => '.+', '_method' => 'GET'));
// add children urls
foreach ($admin->getChildren() as $children) {
$collection->addCollection($children->getRoutes());
}
}
作者:clavier-souri
项目:SonataAdminBundl
/**
* {@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]);
}
作者:Aaik
项目:SonataDoctrinePhpcrAdminBundl
/**
* {@inheritDoc}
*/
public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
} else {
$fieldDescription->setType($type);
}
$this->fixFieldDescription($admin, $fieldDescription);
$admin->addShowFieldDescription($fieldDescription->getName(), $fieldDescription);
switch ($fieldDescription->getMappingType()) {
case ClassMetadata::MANY_TO_ONE:
case ClassMetadata::MANY_TO_MANY:
return;
default:
$list->add($fieldDescription);
}
}
作者:nibsirahsie
项目:AdminBundl
/**
* Note:
* This code is ugly, but there is no better way of doing it.
* For now the append form element action used to add a new row works
* only for direct FieldDescription (not nested one)
*
* @throws \RuntimeException
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param $elementId
* @return void
*/
public function appendFormFieldElement(AdminInterface $admin, $elementId)
{
// retrieve the subject
$formBuilder = $admin->getFormBuilder();
$form = $formBuilder->getForm();
$form->bindRequest($admin->getRequest());
// get the field element
$childFormBuilder = $this->getChildFormBuilder($formBuilder, $elementId);
// retrieve the FieldDescription
$fieldDescription = $admin->getFormFieldDescription($childFormBuilder->getName());
try {
$value = $fieldDescription->getValue($form->getData());
} catch (NoValueException $e) {
$value = null;
}
// retrieve the posted data
$data = $admin->getRequest()->get($formBuilder->getName());
if (!isset($data[$childFormBuilder->getName()])) {
$data[$childFormBuilder->getName()] = array();
}
$objectCount = count($value);
$postCount = count($data[$childFormBuilder->getName()]);
$fields = array_keys($fieldDescription->getAssociationAdmin()->getFormFieldDescriptions());
// for now, not sure how to do that
$value = array();
foreach ($fields as $name) {
$value[$name] = '';
}
// add new elements to the subject
while($objectCount < $postCount) {
// append a new instance into the object
$this->addNewInstance($form->getData(), $fieldDescription);
$objectCount++;
}
$this->addNewInstance($form->getData(), $fieldDescription);
$data[$childFormBuilder->getName()][] = $value;
$form = $admin->getFormBuilder($form->getData())->getForm();
// bind the data
$form->bind($data);
return array($fieldDescription, $form);
}
作者:viral81
项目:ngSimpleCM
/**
* 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)));
}
}
作者:manudatta1
项目:PO
/**
* @param AdminInterface $admin
* @param string $term
* @param int $page
* @param int $offset
*
* @return \Sonata\AdminBundle\Datagrid\PagerInterface
*
* @throws \RuntimeException
*/
public function search(AdminInterface $admin, $term, $page = 0, $offset = 20)
{
$datagrid = $admin->getDatagrid();
$found = false;
foreach ($datagrid->getFilters() as $name => $filter) {
/** @var $filter FilterInterface */
if ($filter->getOption('global_search', false)) {
$filter->setCondition(FilterInterface::CONDITION_OR);
$datagrid->setValue($name, null, $term);
$found = true;
}
}
if (!$found) {
return false;
}
$datagrid->buildPager();
$pager = $datagrid->getPager();
$pager->setPage($page);
$pager->setMaxPerPage($offset);
return $pager;
}
作者:networkin
项目:init-cms-bundl
/**
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* @throws \RuntimeException
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request) {
return;
}
if (!$request->hasSession()) {
return;
}
$adminCode = $request->get('_sonata_admin');
if (!is_null($adminCode)) {
$this->admin = $this->adminPool->getAdminByAdminCode($adminCode);
if (!$this->admin) {
throw new \RuntimeException(sprintf('Unable to find the admin class related to the current controller (%s)', get_class($this)));
}
if (method_exists($this->admin, 'getTrackedActions')) {
foreach ($this->admin->getTrackedActions() as $trackedAction) {
// if an action which is flagged as 'to be tracked' is matching the end of the route: add info to session
if (preg_match('#' . $trackedAction . '$#', $request->get('_route'), $matches)) {
$this->updateTrackedInfo($request->getSession(), '_networking_initcms_admin_tracker', array('url' => $request->getRequestUri(), 'controller' => $this->admin->getBaseControllerName(), 'action' => $trackedAction));
}
}
}
}
}
作者:symbi
项目:orangegate4-analytics-bundl
/**
* return the base template name
*
* @return string the template name
*/
protected function getBaseTemplate()
{
if ($this->isXmlHttpRequest()) {
return $this->admin->getTemplate('ajax');
}
return $this->admin->getTemplate('layout');
}