Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /** inheritdoc */
 public static function getAssets()
 {
     return array_merge(\CMF\Field\Object\Link::getAssets(), array('js' => array('/admin/assets/js/fields/htaccess.js')));
 }
Exemplo n.º 3
0
 public function action_all_links($key = null)
 {
     $defaults = \CMF\Field\Object\Link::getDefaults();
     $options = \CMF\Field\Object\Link::getOptionsStatic($defaults, null);
     if (!$key) {
         $output = array();
         foreach (array_keys($options) as $key2) {
             $output[] = $key2;
         }
         $output = json_encode($output);
     } else {
         $output = json_encode($options[$key]);
     }
     echo $output;
     exit;
 }