|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
|
4
|
|
|
|
|
5
|
|
|
use Groundskeeper\Configuration; |
|
6
|
|
|
use Groundskeeper\Tokens\Element; |
|
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\FlowContent; |
|
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
|
9
|
|
|
use Groundskeeper\Tokens\Token; |
|
10
|
|
|
use Psr\Log\LoggerInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* "menu" element |
|
14
|
|
|
* |
|
15
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-menu-element |
|
16
|
|
|
*/ |
|
17
|
|
|
class Menu extends OpenElement implements FlowContent |
|
18
|
|
|
{ |
|
19
|
1 |
|
protected function getAllowedAttributes() |
|
20
|
|
|
{ |
|
21
|
|
|
$menuAllowedAttributes = array( |
|
22
|
1 |
|
'/^type$/i' => Element::ATTR_CI_ENUM . '("","context","toolbar"|"context")', |
|
23
|
|
|
'/^label$/i' => Element::ATTR_CS_STRING |
|
24
|
1 |
|
); |
|
25
|
|
|
|
|
26
|
1 |
|
return array_merge( |
|
27
|
1 |
|
$menuAllowedAttributes, |
|
28
|
1 |
|
parent::getAllowedAttributes() |
|
29
|
1 |
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
protected function doClean(LoggerInterface $logger) |
|
33
|
|
|
{ |
|
34
|
1 |
|
if (!$this->hasAttribute('type')) { |
|
35
|
1 |
|
$logger->debug('Adding the default type attribute for the "menu" element.'); |
|
36
|
1 |
|
$this->addAttribute('type', 'context'); |
|
37
|
1 |
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) { |
|
40
|
|
|
// Only "li" and ScriptSupporting elements allowed. |
|
41
|
1 |
|
foreach ($this->children as $child) { |
|
42
|
1 |
|
if ($child->getType() == Token::COMMENT) { |
|
43
|
|
|
continue; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
if ($child->getType() != Token::ELEMENT) { |
|
47
|
|
|
$logger->debug('Removing ' . $child . '. Only elements "li", "menuitem", "hr", "menu", and script supporting elements allowed as children of "menu" element.'); |
|
48
|
|
|
$this->removeChild($child); |
|
49
|
|
|
|
|
50
|
|
|
continue; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/// @todo |
|
54
|
1 |
|
} |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|