/**
  * Guess the HREF for the views.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $views = $builder->getViews();
     foreach ($views as &$view) {
         // Only automate it if not set.
         if (!isset($view['attributes']['href'])) {
             $view['attributes']['href'] = $this->url->to($this->request->path() . '?' . array_get($view, 'prefix') . 'view=' . $view['slug']);
         }
     }
     $builder->setViews($views);
 }
 /**
  * Default table views.
  *
  * @param TableBuilder $builder
  */
 public function defaults(TableBuilder $builder)
 {
     if (!($stream = $builder->getTableStream())) {
         return;
     }
     if ($stream->isTrashable() && !$builder->getViews()) {
         $builder->setViews(['all', 'trash']);
     }
 }
示例#3
0
 /**
  * Merge in registered parameters.
  *
  * @param TableBuilder $builder
  */
 public function merge(TableBuilder $builder)
 {
     $views = $builder->getViews();
     foreach ($views as &$parameters) {
         if ($view = $this->views->get(array_get($parameters, 'view'))) {
             $parameters = array_replace_recursive($view, array_except($parameters, ['view']));
         }
     }
     $builder->setViews($views);
 }
 /**
  * Guess the text for the views.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     if (!($module = $this->modules->active())) {
         return;
     }
     $views = $builder->getViews();
     foreach ($views as &$view) {
         // Only automate it if not set.
         if (!isset($view['text'])) {
             $view['text'] = $module->getNamespace('view.' . $view['slug']);
         }
     }
     $builder->setViews($views);
 }
 /**
  * Normalize the view input.
  *
  * @param TableBuilder $builder
  */
 public function normalize(TableBuilder $builder)
 {
     $views = $builder->getViews();
     foreach ($views as $slug => &$view) {
         /**
          * If the slug is numeric and the view is
          * a string then treat the string as both the
          * view and the slug. This is OK as long as
          * there are not multiple instances of this
          * input using the same view which is not likely.
          */
         if (is_numeric($slug) && is_string($view)) {
             $view = ['slug' => $view, 'view' => $view];
         }
         /**
          * If the slug is NOT numeric and the view is a
          * string then use the slug as the slug and the
          * view as the view.
          */
         if (!is_numeric($slug) && is_string($view)) {
             $view = ['slug' => $slug, 'view' => $view];
         }
         /**
          * If the slug is not numeric and the view is an
          * array without a slug then use the slug for
          * the slug for the view.
          */
         if (is_array($view) && !isset($view['slug']) && !is_numeric($slug)) {
             $view['slug'] = $slug;
         }
         /**
          * Make sure we have a view property.
          */
         if (is_array($view) && !isset($view['view'])) {
             $view['view'] = $view['slug'];
         }
         /**
          * Make sure some default parameters exist.
          */
         $view['attributes'] = array_get($view, 'attributes', []);
         /**
          * Move the HREF if any to the attributes.
          */
         if (isset($view['href'])) {
             array_set($view['attributes'], 'href', array_pull($view, 'href'));
         }
         /**
          * Move the target if any to the attributes.
          */
         if (isset($view['target'])) {
             array_set($view['attributes'], 'target', array_pull($view, 'target'));
         }
         /**
          * Make sure the HREF is absolute.
          */
         if (isset($view['attributes']['href']) && is_string($view['attributes']['href']) && !starts_with($view['attributes']['href'], 'http')) {
             $view['attributes']['href'] = url($view['attributes']['href']);
         }
     }
     $builder->setViews($views);
 }