TYPO3 CMS  TYPO3_6-2
AbstractTagBasedViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
22 
28  static private $tagAttributes = array();
29 
37  protected $tag = NULL;
38 
45  protected $tagName = 'div';
46 
52  public function __construct() {
53  $this->registerArgument('additionalAttributes', 'array', 'Additional tag attributes. They will be added directly to the resulting HTML tag.', FALSE);
54  }
55 
66  public function initialize() {
67  parent::initialize();
68  $this->tag->reset();
69  $this->tag->setTagName($this->tagName);
70  if ($this->hasArgument('additionalAttributes') && is_array($this->arguments['additionalAttributes'])) {
71  $this->tag->addAttributes($this->arguments['additionalAttributes']);
72  }
73 
74  if (isset(self::$tagAttributes[get_class($this)])) {
75  foreach (self::$tagAttributes[get_class($this)] as $attributeName) {
76  if ($this->hasArgument($attributeName) && $this->arguments[$attributeName] !== '') {
77  $this->tag->addAttribute($attributeName, $this->arguments[$attributeName]);
78  }
79  }
80  }
81  }
82 
94  protected function registerTagAttribute($name, $type, $description, $required = FALSE, $default = NULL) {
95  $this->registerArgument($name, $type, $description, $required, $default);
96  self::$tagAttributes[get_class($this)][$name] = $name;
97  }
98 
106  protected function registerUniversalTagAttributes() {
107  $this->registerTagAttribute('class', 'string', 'CSS class(es) for this element');
108  $this->registerTagAttribute('dir', 'string', 'Text direction for this HTML element. Allowed strings: "ltr" (left to right), "rtl" (right to left)');
109  $this->registerTagAttribute('id', 'string', 'Unique (in this file) identifier for this HTML element.');
110  $this->registerTagAttribute('lang', 'string', 'Language for this element. Use short names specified in RFC 1766');
111  $this->registerTagAttribute('style', 'string', 'Individual CSS styles for this element');
112  $this->registerTagAttribute('title', 'string', 'Tooltip text of element');
113  $this->registerTagAttribute('accesskey', 'string', 'Keyboard shortcut to access this element');
114  $this->registerTagAttribute('tabindex', 'integer', 'Specifies the tab order of this element');
115  $this->registerTagAttribute('onclick', 'string', 'JavaScript evaluated for the onclick event');
116  }
117 }
registerTagAttribute($name, $type, $description, $required=FALSE, $default=NULL)
registerArgument($name, $type, $description, $required=FALSE, $defaultValue=NULL)