Пример #1
0
 /**
  * {@inheritdoc}
  * <br/>
  * <br/>
  * Available Options :
  * <ul>
  * <li><b>anchor_route</b>  : string <i>Route name. if the route requires arguments, be sur that they are present in 'params'</i></li>
  * <li><b>anchor_params</b> : array|null <i>Route's params.</i></li>
  * <li><b>anchor_args</b>   : array <i>Route's static params.</i></li>
  * <li><b>anchor_text</b>   : string|null <i>Anchor text. If null $view['value'] replace it.</i></li>
  * <li><b>anchor_title</b>  : string|null <i>Anchor title</i></li>
  * </ul>
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver, array $defaultOptions)
 {
     parent::setDefaultOptions($resolver, $defaultOptions);
     $resolver->setDefaults(array('anchor_route' => null, 'anchor_params' => array(), 'anchor_args' => array(), 'anchor_text' => '', 'anchor_title' => ''));
     $resolver->setAllowedTypes(array('anchor_route' => 'string', 'anchor_params' => array('null', 'array'), 'anchor_args' => 'array', 'anchor_text' => 'string', 'anchor_title' => 'string'));
     $resolver->setNormalizers(array('anchor_params' => function (Options $options, $params) {
         if (!is_array($params) || is_null($options['anchor_route'])) {
             return array();
         } else {
             if (count($params) === 0) {
                 $params = array_keys($options['params']);
                 foreach ($params as $name) {
                     if (!is_string($name)) {
                         throw new \UnexpectedValueException('Anchor params must be an associative array');
                     }
                 }
             } else {
                 $diff = array_diff($params, array_keys($options['params']));
                 if (count($diff) > 0) {
                     throw new \UnexpectedValueException('anchor_params (' . implode(',', $diff) . ') must be defined in params');
                 }
             }
         }
         return $params;
     }));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected static function format($format, array $data, array $types = null)
 {
     $datetime = parent::format(null, $data);
     if (!$datetime instanceof \DateTime && $datetime !== null) {
         throw new \RuntimeException('$data must contains one element as a \\Datetime');
     }
     return $datetime;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function buildView(array &$view, ColumnInterface $column, array $data, array $options)
 {
     if ($options['icon'] !== null) {
         parent::buildView($view, $column, $data, $options);
     } else {
         ColumnType::buildView($view, $column, $data, $options);
     }
     $view['text'] = isset($options['text']) ? $options['text'] : $view['value'];
     $view['title'] = $options['desc'];
 }