/**
  * Set the handler's error title.
  *
  * @param  mixed $title The error title.
  * @return self
  */
 public function setErrorTitle($title)
 {
     if (TranslationString::isTranslatable($title)) {
         $this->errorTitle = new TranslationString($title);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * @param string|string[] $name The name of the tag.
  * @return self chainable
  */
 public function setName($name)
 {
     if (TranslationString::isTranslatable($name)) {
         $this->name = new TranslationString($name);
     } else {
         $this->name = null;
     }
     return $this;
 }
 /**
  * Set the object's URL slug.
  *
  * @param mixed $slug The slug.
  * @return RoutableInterface Chainable
  */
 public function setSlug($slug)
 {
     if (TranslationString::isTranslatable($slug)) {
         $this->slug = new TranslationString($slug);
         $values = $this->slug->all();
         foreach ($values as $lang => $val) {
             $this->slug[$lang] = $this->slugify($val);
         }
     } else {
         /** @todo Hack used for regenerating route */
         if (isset($_POST['slug'])) {
             $this->slug = [];
         } else {
             $this->slug = null;
         }
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * Set the label for the file removal button.
  *
  * @param  string|string[] $label The button label.
  * @return self
  */
 public function setRemoveButtonLabel($label)
 {
     if (TranslationString::isTranslatable($label)) {
         $this->removeButtonLabel = new TranslationString($label);
     } else {
         $this->removeButtonLabel = null;
     }
     return $this;
 }
 /**
  * Set the title for the file picker dialog.
  *
  * @param  string|string[] $title The dialog title.
  * @return self
  */
 public function setDialogTitle($title)
 {
     if (TranslationString::isTranslatable($title)) {
         $this->dialogTitle = new TranslationString($title);
     } else {
         $this->dialogTitle = null;
     }
     return $this;
 }
 /**
  * @param mixed $notes The property notes.
  * @return PropertyInterface Chainable
  */
 public function setNotes($notes)
 {
     if (TranslationString::isTranslatable($notes)) {
         $this->notes = new TranslationString($notes);
     } else {
         $this->notes = null;
     }
     return $this;
 }
 /**
  * @param mixed $label The menu item label.
  * @return MenuItem Chainable
  */
 public function setLabel($label)
 {
     if (TranslationString::isTranslatable($label)) {
         $this->label = new TranslationString($label);
     }
     return $this;
 }
 /**
  * Set the sidemenu links.
  *
  * @param string       $linkIdent The link identifier.
  * @param array|object $link      The link object or structure.
  * @throws InvalidArgumentException If the link is invalid.
  * @return self
  */
 public function addLink($linkIdent, $link)
 {
     if (!is_string($linkIdent) && !is_numeric($linkIdent)) {
         throw new InvalidArgumentException('Link identifier must be a string or ');
     }
     $objType = $this->sidemenu()->objType();
     if (is_array($link)) {
         $active = true;
         $name = null;
         $url = null;
         if (isset($link['active'])) {
             $active = !!$link['active'];
         }
         if (isset($link['name']) && TranslationString::isTranslatable($link['name'])) {
             $name = new TranslationString($link['name']);
         }
         if (isset($link['url']) && TranslationString::isTranslatable($link['url'])) {
             $url = new TranslationString($link['url']);
         }
         if ($name === null && $url === null) {
             return $this;
         }
         $isSelected = $linkIdent === $objType;
         if ($isSelected) {
             $this->isSelected(true);
         }
         $this->links[$linkIdent] = ['active' => $active, 'name' => $name, 'url' => $url, 'selected' => $isSelected];
     } else {
         throw new InvalidArgumentException(sprintf('Link must be an associative array, received %2$s', 'MenuItemInterface', is_object($link) ? get_class($link) : gettype($link)));
     }
     return $this;
 }
 /**
  * Set the name of the language
  *
  * Optionally, set the name in other languages.
  *
  * The $name parameter accepts 3 types of arguments:
  * - object (TranslationStringInterface): The data will be copied from the object's.
  * - array: All languages available in the array. The format of the array should
  *   be a hash in the `lang` => `string` format.
  * - string: The value will be assigned to the current language.
  *
  * @param TranslationString|array|string $name Language's name in one or more languages.
  * @return self
  */
 public function setName($name)
 {
     if ($name instanceof TranslationStringInterface) {
         $config = $name->languages();
     } elseif (is_array($name)) {
         $config = ['languages' => array_keys($name), 'default_language' => $this->ident()];
     } else {
         $config = null;
     }
     $this->name = new TranslationString($name, $config);
     return $this;
 }
 /**
  * Retrieve the title of the page.
  *
  * @return TranslationString|string|null
  */
 public function title()
 {
     if (isset($this->title)) {
         return $this->title;
     }
     try {
         $config = $this->objCollectionDashboardConfig();
         if (isset($config['title'])) {
             $this->title = new TranslationString($config['title']);
             return $this->title;
         }
     } catch (Exception $e) {
         $this->logger->error($e->getMessage());
     }
     $model = $this->proto();
     $metadata = $model->metadata();
     $objLabel = null;
     if (!$objLabel && isset($metadata['admin']['lists'])) {
         $adminMetadata = $metadata['admin'];
         $listIdent = filter_input(INPUT_GET, 'collection_ident', FILTER_SANITIZE_STRING);
         if ($listIdent === false || $listIdent === null || $listIdent === '') {
             $listIdent = isset($adminMetadata['default_list']) ? $adminMetadata['default_list'] : '';
         }
         if (isset($adminMetadata['lists'][$listIdent]['label'])) {
             $objLabel = $adminMetadata['lists'][$listIdent]['label'];
             if (TranslationString::isTranslatable($objLabel)) {
                 $objLabel = new TranslationString($objLabel);
             }
         }
     }
     if (!$objLabel && isset($metadata['labels']['all_items'])) {
         $objLabel = $metadata['labels']['all_items'];
         if (TranslationString::isTranslatable($objLabel)) {
             $objLabel = new TranslationString($objLabel);
         }
     }
     if (!$objLabel) {
         $objType = isset($metadata['labels']['name']) ? $metadata['labels']['name'] : null;
         if (TranslationString::isTranslatable($objType)) {
             $objType = new TranslationString($objType);
         }
         $objLabel = new TranslationString(['en' => 'List: {{objType}}', 'fr' => 'Liste : {{objType}}']);
         if ($objType) {
             $objLabel = sprintf(str_replace('{{objType}}', '%s', $objLabel), $objType);
         }
     }
     if ($model && $model->view()) {
         $this->title = $model->render((string) $objLabel, $model);
     } else {
         $this->title = (string) $objLabel;
     }
     return $this->title;
 }
 /**
  * Add a custom localization message.
  *
  * @param  string $ident        The message ID.
  * @param  mixed  $translations The message translations.
  * @throws InvalidArgumentException If the message ID is not a string or the translations are invalid.
  * @return self
  */
 public function addLocalization($ident, $translations)
 {
     if (!is_string($ident)) {
         throw new InvalidArgumentException(sprintf('Translation key must be a string, received %s', is_object($ident) ? get_class($ident) : gettype($ident)));
     }
     if (!TranslationString::isTranslatable($translations)) {
         throw new InvalidArgumentException(sprintf('Invalid translations, received %s', is_object($ident) ? get_class($ident) : gettype($ident)));
     }
     $this->localizations[$ident] = new TranslationString($translations);
     return $this;
 }
Esempio n. 12
0
 /**
  * Default list actions behavior.
  * List actions should come from the collection data
  * pointed out by the collectionIdent.
  * It is still possible to completly override those
  * externally by setting the listActions with the
  * setListActions setter.
  *
  * @todo Convert to Charcoal\Ui\Menu\GenericMenu
  * @return array List actions.
  */
 public function createListActions()
 {
     $collectionConfig = $this->collectionConfig();
     $listActions = [];
     if (isset($collectionConfig['list_actions'])) {
         foreach ($collectionConfig['list_actions'] as $action) {
             if (isset($action['ident'])) {
                 if ($action['ident'] === 'create' && !$this->isObjCreatable()) {
                     continue;
                 }
             } else {
                 $action['ident'] = null;
             }
             if (isset($action['label']) && TranslationString::isTranslatable($action['label'])) {
                 $action['label'] = new TranslationString($action['label']);
             } elseif ($action['ident']) {
                 $action['label'] = ucwords(str_replace(['.', '_'], ' ', $action['ident']));
             } else {
                 continue;
             }
             if (isset($action['url']) && TranslationString::isTranslatable($action['url'])) {
                 $action['url'] = new TranslationString($action['url']);
                 foreach ($action['url']->all() as $lang => $value) {
                     $action['url'][$lang] = $this->render($value);
                 }
             }
             if (isset($action['is_button'])) {
                 $action['isButton'] = !!$action['is_button'];
             } elseif (isset($action['isButton'])) {
                 $action['is_button'] = !!$action['isButton'];
             }
             if (!isset($action['button_type'])) {
                 $action['button_type'] = $action['ident'] === 'create' ? 'info' : 'default';
             }
             $listActions[] = $action;
         }
     }
     return $listActions;
 }
 /**
  *
  */
 public function testSetValStringDefaultLanguage()
 {
     $obj = new TranslationString(null, ['languages' => ['en', 'fr']]);
     $obj->setCurrentLanguage('en');
     $obj->setVal('foo');
     $obj->setCurrentLanguage('fr');
     $obj->setVal('bar');
     $this->assertEquals(['en' => 'foo', 'fr' => 'bar'], $obj->all());
 }
 /**
  * Retrieve the title of the page.
  *
  * @return TranslationString|string|null
  */
 public function title()
 {
     if (isset($this->title)) {
         return $this->title;
     }
     try {
         $config = $this->objEditDashboardConfig();
         if (isset($config['title'])) {
             $this->title = new TranslationString($config['title']);
             return $this->title;
         }
     } catch (Exception $e) {
         $this->logger->error($e->getMessage());
     }
     $obj = $this->obj();
     $objId = $this->objId();
     $objType = $this->objType();
     $metadata = $obj->metadata();
     $objLabel = null;
     if (!$objLabel && isset($metadata['admin']['forms'])) {
         $adminMetadata = $metadata['admin'];
         $formIdent = filter_input(INPUT_GET, 'form_ident', FILTER_SANITIZE_STRING);
         if ($formIdent === false || $formIdent === null || $formIdent === '') {
             $formIdent = isset($adminMetadata['default_form']) ? $adminMetadata['default_form'] : '';
         }
         if (isset($adminMetadata['forms'][$formIdent]['label'])) {
             $objLabel = $adminMetadata['forms'][$formIdent]['label'];
             if (TranslationString::isTranslatable($objLabel)) {
                 $objLabel = new TranslationString($objLabel);
             }
         }
     }
     if (!$objLabel && isset($metadata['labels']['edit_item'])) {
         $objLabel = $metadata['labels']['edit_item'];
         if (TranslationString::isTranslatable($objLabel)) {
             $objLabel = new TranslationString($objLabel);
         }
     }
     if (!$objLabel && isset($metadata['labels']['edit_model'])) {
         $objLabel = $metadata['labels']['edit_model'];
         if (TranslationString::isTranslatable($objLabel)) {
             $objLabel = new TranslationString($objLabel);
         }
     }
     if (!$objLabel) {
         $objType = isset($metadata['labels']['singular_name']) ? $metadata['labels']['singular_name'] : null;
         if (TranslationString::isTranslatable($objType)) {
             $objType = new TranslationString($objType);
         }
         if ($objId) {
             $objLabel = new TranslationString(['en' => 'Edit: {{objType}} #{{id}}', 'fr' => 'Modifier : {{objType}} #{{id}}']);
         } else {
             $objLabel = new TranslationString(['en' => 'Create: {{objType}}', 'fr' => 'Créer : {{objType}}']);
         }
         if ($objType) {
             $objLabel = sprintf(str_replace('{{objType}}', '%s', $objLabel), $objType);
         }
     }
     if ($obj && $obj->view()) {
         $this->title = $obj->render((string) $objLabel, $obj);
     } else {
         $this->title = (string) $objLabel;
     }
     return $this->title;
 }
 /**
  * @return mixed
  */
 public function searchable()
 {
     if ($this->searchable === null) {
         if (isset($this->dualSelectOptions['searchable'])) {
             $searchable = $this->dualSelectOptions['searchable'];
             $label = new TranslationString(['en' => 'Search…', 'fr' => 'Recherche…']);
             $defaultOptions = ['left' => ['placeholder' => $label], 'right' => ['placeholder' => $label]];
             if (is_bool($searchable) && $searchable) {
                 $searchable = $defaultOptions;
             } elseif (is_array($searchable)) {
                 $lists = ['left', 'right'];
                 foreach ($lists as $ident) {
                     if (isset($searchable[$ident]['placeholder'])) {
                         $placeholder = $searchable[$ident]['placeholder'];
                     } elseif (isset($searchable['placeholder'])) {
                         $placeholder = $searchable['placeholder'];
                     }
                     if (isset($placeholder) && TranslationString::isTranslatable($placeholder)) {
                         $searchable[$ident]['placeholder'] = new TranslationString($placeholder);
                     } else {
                         $searchable[$ident]['placeholder'] = $label;
                     }
                 }
             } else {
                 $searchable = false;
             }
         } else {
             $searchable = false;
         }
         $this->searchable = $searchable;
     }
     return $this->searchable;
 }
 /**
  * Set the form control's placeholder.
  *
  * A placeholder is a hint to the user of what can be entered
  * in the property control.
  *
  * @param mixed $placeholder The placeholder attribute.
  * @return AbstractPropertyInput Chainable
  */
 public function setPlaceholder($placeholder)
 {
     if (TranslationString::isTranslatable($placeholder)) {
         $this->placeholder = new TranslationString($placeholder);
         $this->placeholder->isRendered = false;
     }
     return $this;
 }