コード例 #1
0
 /**
  * Guess the sections title.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If title is set then skip it.
         if (isset($section['title'])) {
             continue;
         }
         $module = $this->modules->active();
         $title = $module->getNamespace('section.' . $section['slug'] . '.title');
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         $title = $module->getNamespace('addon.section.' . $section['slug']);
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         if (!isset($section['title']) && $this->config->get('streams::system.lazy_translations')) {
             $section['title'] = ucwords($this->string->humanize($section['slug']));
         }
         if (!isset($section['title'])) {
             $section['title'] = $title;
         }
     }
     $builder->setSections($sections);
 }
コード例 #2
0
 /**
  * Make a route.
  *
  * @param                    $route
  * @param  array             $parameters
  * @return mixed|null|string
  */
 public function make($route, array $parameters = [])
 {
     if (method_exists($this, $method = $this->str->camel(str_replace('.', '_', $route)))) {
         $parameters['parameters'] = $parameters;
         return $this->container->call([$this, $method], $parameters);
     }
     if (!str_contains($route, '.') && ($stream = $this->entry->getStreamSlug())) {
         $route = "{$stream}.{$route}";
     }
     if (!str_contains($route, '::') && ($namespace = $this->locator->locate($this->entry))) {
         $route = "{$namespace}::{$route}";
     }
     return $this->url->make($route, $this->entry, $parameters);
 }
コード例 #3
0
 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /**
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         if (!isset($button['button'])) {
             continue;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         if ((!isset($button['text']) || !$this->translator->has($button['text'])) && $this->config->get('streams::system.lazy_translations')) {
             $button['text'] = $this->string->humanize(array_get($button, 'slug', $button['button']));
         }
     }
     $builder->setButtons($buttons);
 }
コード例 #4
0
 /**
  * Guess some table table filter placeholders.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $filters = $builder->getFilters();
     $stream = $builder->getTableStream();
     foreach ($filters as &$filter) {
         // Skip if we already have a placeholder.
         if (isset($filter['placeholder'])) {
             continue;
         }
         // Get the placeholder off the assignment.
         if ($stream && ($assignment = $stream->getAssignment(array_get($filter, 'field')))) {
             /*
              * Always use the field name
              * as the placeholder. Placeholders
              * that are assigned otherwise usually
              * feel out of context:
              *
              * "Choose an option..." in the filter
              * would just be weird.
              */
             $placeholder = $assignment->getFieldName();
             if ($this->translator->has($placeholder)) {
                 $filter['placeholder'] = $placeholder;
             }
         }
         if (!($module = $this->modules->active())) {
             continue;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.placeholder');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.name');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         if (!array_get($filter, 'placeholder')) {
             $filter['placeholder'] = $filter['slug'];
         }
         if (!$this->translator->has($filter['placeholder']) && $this->config->get('streams::system.lazy_translations')) {
             $filter['placeholder'] = ucwords($this->string->humanize($filter['placeholder']));
         }
     }
     $builder->setFilters($filters);
 }
コード例 #5
0
 /**
  * Guess the field labels.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $stream = $builder->getFormStream();
     foreach ($fields as &$field) {
         $locale = array_get($field, 'locale');
         /**
          * If the label are already set then use it.
          */
         if (isset($field['label'])) {
             if (str_is('*::*', $field['label'])) {
                 $field['label'] = trans($field['label'], [], null, $locale);
             }
             continue;
         }
         /**
          * If we don't have a field then we
          * can not really guess anything here.
          */
         if (!isset($field['field'])) {
             continue;
         }
         /**
          * No stream means we can't
          * really do much here.
          */
         if (!$stream instanceof StreamInterface) {
             continue;
         }
         $assignment = $stream->getAssignment($field['field']);
         $object = $stream->getField($field['field']);
         /**
          * No assignment means we still do
          * not have anything to do here.
          */
         if (!$assignment instanceof AssignmentInterface) {
             continue;
         }
         /**
          * Next try using the fallback assignment
          * label system as generated verbatim.
          */
         $label = $assignment->getLabel() . '.default';
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale)) {
             $field['label'] = trans($label, [], null, $locale);
         }
         /**
          * Next try using the default assignment
          * label system as generated verbatim.
          */
         $label = $assignment->getLabel();
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale) && is_string($translated = trans($label, [], null, $locale))) {
             $field['label'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['label']) && $label && !str_is('*::*', $label)) {
             $field['label'] = $label;
         }
         /**
          * Next try using the generic assignment
          * label system without the stream identifier.
          */
         $label = explode('.', $assignment->getLabel());
         array_pop($label);
         $label = implode('.', $label);
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale) && is_string($translated = trans($label, [], null, $locale))) {
             $field['label'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['label']) && $label && !str_is('*::*', $label)) {
             $field['label'] = $label;
         }
         /**
          * Next try using the default field
          * label system as generated verbatim.
          */
         $label = $object->getName();
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale) && is_string($translated = trans($label, [], null, $locale))) {
             $field['label'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['label']) && $label && !str_is('*::*', $label)) {
             $field['label'] = $label;
         }
         /**
          * If the field is still untranslated and
          * we're not debugging then humanize the slug
          * in leu of displaying an untranslated key.
          */
         if (!isset($field['label']) && $this->config->get('streams::system.lazy_translations')) {
             $field['label'] = $this->string->humanize($field['field']);
         }
     }
     $builder->setFields($fields);
 }
コード例 #6
0
 /**
  * Guess the field for a column.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $columns = $builder->getColumns();
     $stream = $builder->getTableStream();
     $module = $this->modules->active();
     foreach ($columns as &$column) {
         /*
          * If the heading is already set then
          * we don't have anything to do.
          */
         if (isset($column['heading'])) {
             continue;
         }
         /*
          * If the heading is false, then no
          * header is desired at all.
          */
         if (isset($column['heading']) && $column['heading'] === false) {
             continue;
         }
         /*
          * No stream means we can't
          * really do much here.
          */
         if (!$stream instanceof StreamInterface) {
             continue;
         }
         if (!isset($column['field']) && is_string($column['value'])) {
             $column['field'] = $column['value'];
         }
         /*
          * If the heading matches a field
          * with dot format then reduce it.
          */
         if (isset($column['field']) && preg_match("/^entry.([a-zA-Z\\_]+)/", $column['field'], $match)) {
             $column['field'] = $match[1];
         }
         /*
          * Detect some built in columns.
          */
         if (in_array($column['field'], ['id', 'created_at', 'created_by', 'updated_at', 'updated_by'])) {
             $column['heading'] = 'streams::entry.' . $column['field'];
             continue;
         }
         /*
          * Detect entry title.
          */
         if (in_array($column['field'], ['view_link', 'edit_link']) && ($field = $stream->getTitleField())) {
             $column['heading'] = $field->getName();
             continue;
         }
         $field = $stream->getField(array_get($column, 'field'));
         /*
          * Detect the title column.
          */
         $title = $stream->getTitleField();
         if ($title && !$field && $column['field'] == 'title' && $this->translator->has($heading = $title->getName())) {
             $column['heading'] = $heading;
         }
         /*
          * Use the name from the field.
          */
         if ($field && ($heading = $field->getName())) {
             $column['heading'] = $heading;
         }
         /*
          * If no field look for
          * a name anyways.
          */
         if ($module && !$field && $this->translator->has($heading = $module->getNamespace('field.' . $column['field'] . '.name'))) {
             $column['heading'] = $heading;
         }
         /*
          * If no translatable heading yet and
          * the heading matches the value (default)
          * then humanize the heading value.
          */
         if (!isset($column['heading']) && $this->config->get('streams::system.lazy_translations')) {
             $column['heading'] = ucwords($this->string->humanize($column['field']));
         }
         /*
          * If we have a translatable heading and
          * the heading does not have a translation
          * then humanize the heading value.
          */
         if (isset($column['heading']) && str_is('*.*.*::*', $column['heading']) && !$this->translator->has($column['heading']) && $this->config->get('streams::system.lazy_translations')) {
             $column['heading'] = ucwords($this->string->humanize($column['field']));
         }
         /*
          * Last resort.
          */
         if ($module && !isset($column['heading'])) {
             $column['heading'] = $module->getNamespace('field.' . $column['field'] . '.name');
         }
     }
     $builder->setColumns($columns);
 }
コード例 #7
0
 /**
  * Return an excerpt of the text.
  *
  * @param int    $length
  * @param string $ending
  * @return string
  */
 public function excerpt($length = 100, $ending = '...')
 {
     return $this->str->truncate($this->text(), $length, $ending);
 }