Example #1
0
 public function testNameToId()
 {
     $result = HtmlHelper::nameToId('field');
     $this->assertEquals('field', $result);
     $result = HtmlHelper::nameToId('field[key1]');
     $this->assertEquals('field-key1', $result);
     $result = HtmlHelper::nameToId('field[][key1]');
     $this->assertEquals('field--key1', $result);
     $result = HtmlHelper::nameToId('field[key1][key2][key3]');
     $this->assertEquals('field-key1-key2-key3', $result);
 }
Example #2
0
 /**
  * Returns a value suitable for the field id property.
  * @param  string $suffix Specify a suffix string
  * @return string
  */
 public function getId($suffix = null)
 {
     $id = 'field';
     if ($this->arrayName) {
         $id .= '-' . $this->arrayName;
     }
     $id .= '-' . $this->fieldName;
     if ($suffix) {
         $id .= '-' . $suffix;
     }
     if ($this->idPrefix) {
         $id = $this->idPrefix . '-' . $id;
     }
     return HtmlHelper::nameToId($id);
 }
Example #3
0
 protected function makeTableWidget()
 {
     $config = $this->makeConfig((array) $this->config);
     $config->dataSource = 'client';
     // It's safe to use the field name as an alias
     // as field names do not repeat in forms. This
     // approach lets to access the table data by the
     // field name in POST requests directly (required
     // in some edge cases).
     $config->alias = studly_case(HtmlHelper::nameToId($this->fieldName)) . 'datatable';
     $table = new Table($this->controller, $config);
     $table->bindEvent('table.getDropdownOptions', [$this, 'getDataTableOptions']);
     return $table;
 }
Example #4
0
 /**
  * Returns a unique ID for this widget. Useful in creating HTML markup.
  * @param string $suffix An extra string to append to the ID.
  * @return string A unique identifier.
  */
 public function getId($suffix = null)
 {
     $id = class_basename(get_called_class());
     if ($this->alias != $this->defaultAlias) {
         $id .= '-' . $this->alias;
     }
     if ($suffix !== null) {
         $id .= '-' . $suffix;
     }
     return HtmlHelper::nameToId($id);
 }
Example #5
0
 protected function makeTableWidget()
 {
     $config = $this->makeConfig((array) $this->config);
     $config->dataSource = 'client';
     $config->alias = studly_case(HtmlHelper::nameToId($this->fieldName)) . 'datatable';
     $config->fieldName = $this->fieldName;
     $table = new Table($this->controller, $config);
     $table->bindEvent('table.getDropdownOptions', [$this, 'getDataTableOptions']);
     return $table;
 }
Example #6
0
 /**
  * Returns a value suitable for the column id property.
  * @param  string $suffix Specify a suffix string
  * @return string
  */
 public function getId($suffix = null)
 {
     $id = 'column';
     $id .= '-' . $this->columnName;
     if ($suffix) {
         $id .= '-' . $suffix;
     }
     return HtmlHelper::nameToId($id);
 }
Example #7
0
 /**
  * Makes a widget object from a form field object.
  *
  * @param $field
  * @return \Backend\Traits\FormWidgetBase|null
  */
 protected function makeFormFieldWidget($field)
 {
     if ($field->type !== 'widget') {
         return null;
     }
     if (isset($this->formWidgets[$field->fieldName])) {
         return $this->formWidgets[$field->fieldName];
     }
     $widgetConfig = $this->makeConfig($field->config);
     $widgetConfig->alias = $this->alias . studly_case(HtmlHelper::nameToId($field->fieldName));
     $widgetConfig->sessionKey = $this->getSessionKey();
     $widgetConfig->previewMode = $this->previewMode;
     $widgetConfig->model = $this->model;
     $widgetConfig->data = $this->data;
     $widgetName = $widgetConfig->widget;
     $widgetClass = $this->widgetManager->resolveFormWidget($widgetName);
     if (!class_exists($widgetClass)) {
         throw new ApplicationException(Lang::get('backend::lang.widget.not_registered', ['name' => $widgetClass]));
     }
     $widget = $this->makeFormWidget($widgetClass, $field, $widgetConfig);
     /*
      * If options config is defined, request options from the model.
      */
     if (isset($field->config['options'])) {
         $field->options(function () use($field) {
             $fieldOptions = $field->config['options'];
             if ($fieldOptions === true) {
                 $fieldOptions = null;
             }
             $fieldOptions = $this->getOptionsFromModel($field, $fieldOptions);
             return $fieldOptions;
         });
     }
     return $this->formWidgets[$field->fieldName] = $widget;
 }
Example #8
0
 /**
  * @deprecated Moved to October\Rain\Html\Helper::nameToId
  */
 public static function evalHtmlId($string)
 {
     traceLog('Str::evalHtmlId has been deprecated, use October\\Rain\\Html\\Helper::nameToId instead.');
     return HtmlHelper::nameToId($string);
 }
Example #9
0
 /**
  * Makes a widget object from a form field object.
  */
 protected function makeFormFieldWidget($field)
 {
     if ($field->type != 'widget') {
         return null;
     }
     if (isset($this->formWidgets[$field->fieldName])) {
         return $this->formWidgets[$field->fieldName];
     }
     $widgetConfig = $this->makeConfig($field->config);
     $widgetConfig->alias = $this->alias . studly_case(HtmlHelper::nameToId($field->fieldName));
     $widgetConfig->sessionKey = $this->getSessionKey();
     $widgetConfig->previewMode = $this->previewMode;
     $widgetConfig->model = $this->model;
     $widgetConfig->data = $this->data;
     $widgetName = $widgetConfig->widget;
     $widgetClass = $this->widgetManager->resolveFormWidget($widgetName);
     if (!class_exists($widgetClass)) {
         throw new ApplicationException(Lang::get('backend::lang.widget.not_registered', ['name' => $widgetClass]));
     }
     $widget = $this->makeFormWidget($widgetClass, $field, $widgetConfig);
     return $this->formWidgets[$field->fieldName] = $widget;
 }
Example #10
0
 /**
  * Returns a unique ID for this widget. Useful in creating HTML markup.
  */
 public function getId($suffix = null)
 {
     $id = parent::getId($suffix);
     $id .= '-' . $this->fieldName;
     return HtmlHelper::nameToId($id);
 }
Example #11
0
 /**
  * Returns a value suitable for the scope id property.
  */
 public function getId($suffix = null)
 {
     $id = 'scope';
     $id .= '-' . $this->scopeName;
     if ($suffix) {
         $id .= '-' . $suffix;
     }
     if ($this->idPrefix) {
         $id = $this->idPrefix . '-' . $id;
     }
     return HtmlHelper::nameToId($id);
 }