/** * Create button * * @param Array $data * @return Html * @throws \Mesour\DataGrid\Grid_Exception */ public function create($data = NULL) { if (empty($data) === FALSE) { $this->data = $data; } if (is_null($this->presenter)) { throw new Grid_Exception('Presenter is not set for Button.'); } if (isset($this->option[self::BUTTON_CLASSES])) { $class = $this->option[self::BUTTON_CLASSES]; } else { $class = 'btn btn-sm ' . (array_key_exists(self::CLASS_NAME, $this->option) ? $this->option[self::CLASS_NAME] . ' ' : ''); $class .= $this->option[self::TYPE]; } $button = Html::el('a'); if (array_key_exists(self::CONFIRM, $this->option)) { $button->addAttributes(array('onclick' => "return confirm('" . addslashes($this->getTranslator() ? $this->getTranslator()->translate($this->option[self::CONFIRM]) : $this->option[self::CONFIRM]) . "');")); } if (array_key_exists(self::TITLE, $this->option)) { $button->addAttributes(array('title' => $this->getTranslator() ? $this->getTranslator()->translate($this->option[self::TITLE]) : $this->option[self::TITLE])); } if (array_key_exists(self::ATTRIBUTES, $this->option) && is_array($this->option[self::ATTRIBUTES])) { foreach ($this->option[self::ATTRIBUTES] as $name => $value) { if ($value instanceof Link) { if (!$this->option[self::DISABLED]) { $output = $this->addLinkAttr($button, $name, $value); if ($output === FALSE) { $this->option[self::DISABLED] = TRUE; } } } else { $button->addAttributes(array($name => Link::parseValue($value, $this->data))); } } } if ($this->option[self::DISABLED]) { $class .= ' disabled'; } $button->addAttributes(array('class' => $class)); $translated_text = $this->getTranslator() ? $this->getTranslator()->translate($this->option[self::TEXT]) : $this->option[self::TEXT]; if ($this->option[self::ICON_POSITION] === 'right') { $button->add($translated_text); } if (array_key_exists(self::ICON, $this->option) && is_string($this->option[self::ICON]) || array_key_exists(self::ICON_CLASSES, $this->option)) { if (isset($this->option[self::ICON_CLASSES])) { $attributes = array('class' => $this->option[self::ICON_CLASSES]); } else { $attributes = array('class' => 'glyphicon ' . $this->option[self::ICON]); if (isset($this->option[self::ICON_COLOR])) { $attributes['style'] = 'color:' . $this->option[self::ICON_COLOR]; } } $button->add(Html::el('b', $attributes)); $button->add(' '); } if ($this->option[self::ICON_POSITION] === 'left') { $button->add($translated_text); } return $button; }
public function getBodyAttributes($data) { if (!empty($this->option[self::ATTRIBUTES]) && is_array($this->option[self::ATTRIBUTES])) { foreach ($this->option[self::ATTRIBUTES] as $key => $value) { $this->option[self::ATTRIBUTES][$key] = Link::parseValue($value, $data); } return $this->option[self::ATTRIBUTES]; } return array(); }