Esempio n. 1
0
 /**
  * Render the nav for the provided component.
  *
  * @param ComponentInterface $component
  * @return string
  */
 public function direct(ComponentInterface $component, array $options = [])
 {
     if ($component instanceof CrudInterface) {
         $singularTitle = $component->getPrimaryModel()->getSingularTitle();
     } else {
         $singularTitle = $component->getTitle();
     }
     if ($component instanceof CrudInterface) {
         $pluralTitle = $component->getPrimaryModel()->getPluralTitle();
     } else {
         $pluralTitle = $component->getTitle();
     }
     if (!isset($options['createUrl'])) {
         $options['createUrl'] = null;
     }
     if (!isset($options['deletedRecordsModifier'])) {
         $options['deletedRecordsModifier'] = null;
     }
     return $this->partial('admin-component-nav.phtml', array('permissions' => $component->getPermissions(), 'singularTitle' => $singularTitle, 'pluralTitle' => $pluralTitle, 'createUrl' => $options['createUrl'], 'deletedRecordsModifier' => $options['deletedRecordsModifier']));
 }
Esempio n. 2
0
 /**
  * Generate a URL for the provided page and params that will match the
  * Silex routes set up by this class.
  *
  * @param ComponentInterface $component
  * @param string $page
  * @param array $params
  * @return string
  */
 public function url(ComponentInterface $component, $page, array $params = array())
 {
     $url = '/admin/' . $component->getName() . '/' . $this->application['inflector']->hyphenize($page) . $this->assembleQueryString($params, '?');
     if (Pimple::hasResource('url-filter')) {
         /* @var $filter callable */
         $filter = Pimple::getResource('url-filter');
         $url = $filter($url);
     }
     return $url;
 }
Esempio n. 3
0
 /**
  * Check to see if this component is currently being accessed.  We do this
  * manually because we want to know whether the component is in use before
  * WP would itself be able to tell us.  This allows us to dispatch pages on
  * admin_init, which is early enough in the process that we can easily enqueue
  * other resources.  Also, this gives us the chance to run code before WP has
  * rendered any output.
  *
  *
  * @return boolean
  */
 protected function componentIsCurrentlyActive(ComponentInterface $component)
 {
     return preg_match('/^' . $component->getSlug() . '($|\\/)/i', $component->getRequest()->getQuery('page')) || $component->getSlug() === $component->getRequest()->getPost('action');
 }
Esempio n. 4
0
 /**
  * As the component this page belongs to for a URL matching the provided
  * page and query string parameters.  This method should always be used for
  * generating URLs in your components so that it will play nicely with
  * various WP integration points like submenus.
  *
  * @param string $page
  * @param array $params
  * @return string
  */
 public function url($page, array $params = array())
 {
     return $this->component->url($page, $params);
 }