예제 #1
0
 /**
  * Renders the field's form element for editing in the admin site
  * @see \Admin::getFieldSettings()
  * @param mixed $value The current value of the property, if there is one
  * @param array $settings Field settings, created through \Admin::getFieldSettings()
  * @param object $model The model, if it is being edited.
  * @return string The form control
  */
 public static function displayForm($value, &$settings, $model)
 {
     $class = get_called_class();
     $settings = static::settings($settings);
     $include_label = isset($settings['label']) ? $settings['label'] : true;
     $required = isset($settings['required']) ? $settings['required'] : false;
     $errors = $model->getErrorsForField($settings['mapping']['fieldName']);
     $has_errors = count($errors) > 0;
     $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge');
     if (!isset($input_attributes['id'])) {
         $input_attributes['id'] = 'form_' . $settings['mapping']['fieldName'];
     }
     $attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings));
     $label_text = $settings['title'] . ($required ? ' *' : '');
     // Translation?
     if (\CMF::$lang_enabled && !\CMF::langIsDefault() && isset($settings['mapping']['columnName']) && $model->isTranslatable($settings['mapping']['columnName'])) {
         // If there is no translation
         if (!$model->hasTranslation($settings['mapping']['columnName'])) {
             $attributes['class'] .= ' no-translation';
             $input_attributes['class'] .= ' no-translation';
             $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" />&nbsp; ' . $label_text;
         } else {
             $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" />&nbsp; ' . $label_text;
         }
     }
     // Description?
     $description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : '';
     // Build the input
     $input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />';
     // Build the label
     $label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $settings['mapping']['fieldName']), $label_text . ($has_errors ? ' - ' . $errors[0] : ''));
     // Prepend or append things...
     if (isset($settings['prepend'])) {
         $input = html_tag('div', array('class' => 'input-prepend'), html_tag('span', array('class' => 'add-on'), $settings['prepend']) . $input);
     }
     if (isset($settings['append'])) {
         $input = html_tag('div', array('class' => 'input-append'), $input . html_tag('span', array('class' => 'add-on'), $settings['append']));
     }
     // Don't wrap the input if wrap is set to false
     if (isset($settings['wrap']) && $settings['wrap'] === false) {
         return $label . $input;
     }
     // Add the 'keep updated' control if the field has a template
     if (isset($settings['template']) && !empty($settings['template'])) {
         $attributes['class'] .= ' field-with-controls field-with-template';
         $auto_update_setting = 'settings[' . $settings['mapping']['fieldName'] . '][auto_update]';
         $auto_update_content = \Form::hidden($auto_update_setting, '0', array()) . html_tag('label', array('class' => 'checkbox auto-update-label'), \Form::checkbox($auto_update_setting, '1', \Arr::get($settings, 'auto_update', true), array('class' => 'auto-update')) . strtolower(\Lang::get('admin.common.auto_update')));
         $auto_update = html_tag('div', array('class' => 'controls-top'), $auto_update_content);
         $label .= $auto_update;
         return array('content' => html_tag('div', $attributes, $label . $description . $input) . '<div class="clear"><!-- --></div>', 'widget' => false, 'assets' => array('js' => array('/admin/assets/js/twig.min.js', '/admin/assets/js/fields/template.js')), 'js_data' => $settings);
     }
     return html_tag('div', $attributes, $label . $description . $input);
 }
예제 #2
0
 /** inheritdoc */
 public static function displayForm($value, &$settings, $model)
 {
     $settings = static::settings($settings);
     $include_label = isset($settings['label']) ? $settings['label'] : true;
     $required = isset($settings['required']) ? $settings['required'] : false;
     $errors = $model->getErrorsForField($settings['mapping']['fieldName']);
     $has_errors = count($errors) > 0;
     $attributes = array('class' => 'controls control-group ' . ($has_errors ? ' error' : ''));
     $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge');
     //add redactor to the class for the field
     $input_attributes['class'] = $input_attributes['class'] . " redactor";
     $label_text = $settings['title'] . ($required ? ' *' : '');
     $input = \Form::textarea($settings['mapping']['fieldName'], strval($value), $input_attributes);
     // Translation?
     if (\CMF::$lang_enabled && !\CMF::langIsDefault() && $model->isTranslatable($settings['mapping']['columnName'])) {
         // If there is no translation
         if (!$model->hasTranslation($settings['mapping']['columnName'])) {
             $attributes['class'] .= ' no-translation';
             $label_text = '<span class="no-translation"><img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" />&nbsp; ' . $label_text . '</span>';
         } else {
             $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" />&nbsp; ' . $label_text;
         }
     }
     // Build the label
     $label = !$include_label ? '' : \Form::label($label_text . ($has_errors ? ' - ' . $errors[0] : ''), $settings['mapping']['fieldName'], array('class' => 'item-label'));
     // Set up required information for any links specified
     if (isset($settings['links']) && is_array($settings['links'])) {
         $links = array();
         foreach ($settings['links'] as $link_type => $link) {
             if (!class_exists($link_type)) {
                 continue;
             }
             $link['table_name'] = \CMF\Admin::getTableForClass($link_type);
             $link['singular'] = $link_type::singular();
             $link['plural'] = $link_type::plural();
             $link['icon'] = $link_type::icon();
             $links[$link_type] = $link;
         }
         $settings['links'] = $links;
     }
     // Return only the field and label if no wrap is required
     if (isset($settings['wrap']) && $settings['wrap'] === false) {
         return $label . $input;
     }
     // Return the widget
     if (isset($settings['widget']) && $settings['widget'] === true) {
         return array('assets' => array(), 'content' => $input, 'widget' => true, 'widget_title' => $label_text, 'widget_icon' => 'align-left', 'js_data' => $settings);
     }
     // Return the normal field
     return array('assets' => array(), 'content' => html_tag('div', $attributes, $label . $input), 'widget' => false, 'js_data' => $settings);
 }
예제 #3
0
 /** inheritdoc */
 public static function displayForm($value, &$settings, $model)
 {
     $required = isset($settings['required']) ? $settings['required'] : false;
     $errors = $model->getErrorsForField($settings['mapping']['fieldName']);
     $has_errors = count($errors) > 0;
     $input_attributes = array('class' => 'input input-xxlarge');
     $attributes = array('class' => 'field-type-link controls control-group' . ($has_errors ? ' error' : ''));
     $href_name = $settings['mapping']['fieldName'] . '[href]';
     $value['href'] = isset($value['href']) ? $value['href'] : null;
     $label_text = $settings['title'] . ($required ? ' *' : '');
     // Translation?
     if (\CMF::$lang_enabled && !\CMF::langIsDefault() && isset($settings['mapping']['columnName']) && $model->isTranslatable($settings['mapping']['columnName'])) {
         // If there is no translation
         if (!$model->hasTranslation($settings['mapping']['columnName'])) {
             $attributes['class'] .= ' no-translation';
             $input_attributes['class'] .= ' no-translation';
             $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" />&nbsp; ' . $label_text;
         } else {
             $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" />&nbsp; ' . $label_text;
         }
     }
     // EXTERNAL CHECKBOX
     $external_name = $settings['mapping']['fieldName'] . '[external]';
     $external_value = \Arr::get($value, 'external', false);
     $external = \Form::hidden($external_name, '0') . html_tag('label', array('class' => 'checkbox external-checkbox'), \Form::checkbox($external_name, '1', $external_value, array()) . ' custom');
     $label = \Form::label($label_text . ($has_errors ? ' - ' . $errors[0] : ''), $href_name, array('class' => 'item-label')) . $external . html_tag('div', array('class' => 'clear'), '&nbsp;');
     if ($external_value) {
         $attributes['class'] .= ' external';
     }
     // EXTERNAL INPUT CONTENT
     $href_value_ext = $external_value ? $value['href'] : '';
     $ext_input = \Form::input($href_name, $href_value_ext, $input_attributes);
     $ext_content = html_tag('div', array('class' => 'external-link'), $ext_input);
     // INTERNAL DROPDOWN CONTENT
     $options = static::getOptions($settings, $model);
     $href_value_int = $external_value ? '' : $value['href'];
     // Check if the value is actually an alias
     if (!empty($href_value_int)) {
         $url_value = \CMF\Model\URL::find($href_value_int);
         if ($url_value && ($alias = $url_value->alias)) {
             $href_value_int = $alias->id;
         }
     }
     $input = \Form::select($href_name, $href_value_int, $options, $input_attributes);
     $int_content = html_tag('div', array('class' => 'internal-link'), $input);
     return html_tag('div', $attributes, $label . $int_content . $ext_content) . html_tag('div', array(), '');
 }
예제 #4
0
 /** inheritdoc */
 public static function displayForm($value, &$settings, $model)
 {
     $include_label = isset($settings['label']) ? $settings['label'] : true;
     $target_class = $settings['mapping']['targetEntity'];
     if (is_null($value) || !$value instanceof $target_class) {
         $value = new $target_class();
     }
     // Show a simple alias form if the input var is set
     if (\Input::param('alias', false) !== false) {
         $linkValue = array();
         if (!empty($value)) {
             $linkValue['href'] = $value->isExternal() ? $value->url : strval($value->id);
             $linkValue['external'] = $value->isExternal();
         }
         return \CMF\Field\Object\Link::displayForm($linkValue, $settings, $model);
     }
     $model_class = get_class($model);
     $errors = $model->getErrorsForField($settings['mapping']['fieldName']);
     $has_errors = count($errors) > 0;
     $attributes = array('class' => 'field-type-url controls control-group' . ($has_errors ? ' error' : ''));
     $slug_name = $settings['mapping']['fieldName'] . '[slug]';
     $label_text = $settings['title'] . ($has_errors ? ' - ' . $errors[0] : '');
     if (\CMF::$lang_enabled && !\CMF::langIsDefault()) {
         if (!$value->hasTranslation('slug')) {
             $attributes['class'] .= ' no-translation';
             $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" />&nbsp; ' . $label_text;
         } else {
             $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" />&nbsp; ' . $label_text;
         }
     }
     $keep_updated_setting = 'settings[' . $settings['mapping']['fieldName'] . '][keep_updated]';
     $keep_updated = \Form::hidden($keep_updated_setting, '0', array()) . html_tag('label', array('class' => 'checkbox keep-updated'), \Form::checkbox($keep_updated_setting, '1', \Arr::get($settings, 'keep_updated', true), array()) . strtolower(\Lang::get('admin.common.auto_update')));
     $input = \Form::input($slug_name, $value->slug, array('class' => 'input-xlarge', 'data-copy-from' => implode(',', $model_class::slugFields())));
     $label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $slug_name), $label_text) . $keep_updated . html_tag('div', array('class' => 'clear'), '&nbsp;');
     $prefix = $value->prefix;
     $prepend = html_tag('span', array('class' => 'add-on'), empty($prefix) ? '/' : $prefix);
     $input = html_tag('div', array('class' => 'input-prepend'), $prepend . $input);
     $clear = '<div class="clear"><!-- --></div>';
     if (isset($settings['wrap']) && $settings['wrap'] === false) {
         return $label . $input;
     }
     return html_tag('div', $attributes, $label . $input) . $clear;
 }