-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathStructureTagTrait.php
62 lines (54 loc) · 1.53 KB
/
StructureTagTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Sulu\Bundle\ArticleBundle\Metadata;
use Sulu\Bundle\ArticleBundle\Admin\ArticleAdmin;
use Sulu\Component\Content\Metadata\StructureMetadata;
/**
* Encapsulates function to extract configuration from structure-metadata.
*/
trait StructureTagTrait
{
/**
* Returns type for given structure-metadata.
*
* @return mixed
*/
protected function getType(StructureMetadata $metadata, ?string $default = 'default')
{
return $this->getTagAttribute($metadata, ArticleAdmin::STRUCTURE_TAG_TYPE, 'type', $default);
}
/**
* Returns multipage-configuration for given structure-metadata.
*
* @return mixed
*/
protected function getMultipage(StructureMetadata $metadata)
{
return $this->getTagAttribute($metadata, ArticleAdmin::STRUCTURE_TAG_MULTIPAGE, 'enabled', false);
}
/**
* Returns attribute for given tag in metadata.
*
* @param mixed $default
*
* @return mixed
*/
private function getTagAttribute(StructureMetadata $metadata, string $tag, string $attribute, $default)
{
if (!$metadata->hasTag($tag)) {
return $default;
}
$tag = $metadata->getTag($tag);
if (!\array_key_exists($attribute, $tag['attributes'])) {
return $default;
}
return $tag['attributes'][$attribute];
}
}