‪TYPO3CMS  9.5
RenderableVariant.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
20 
27 {
28 
32  protected ‪$identifier;
33 
37  protected ‪$options;
38 
42  protected ‪$renderable;
43 
47  protected ‪$condition = '';
48 
52  protected ‪$applied = false;
53 
60  public function ‪__construct(
61  string ‪$identifier,
62  array ‪$options,
64  ) {
65  if ('' === ‪$identifier) {
66  throw new ‪IdentifierNotValidException('The given variant identifier was empty.', 1519998923);
67  }
68  $this->identifier = ‪$identifier;
69  $this->renderable = ‪$renderable;
70 
71  if (isset(‪$options['condition']) && is_string(‪$options['condition'])) {
72  $this->condition = ‪$options['condition'];
73  }
74 
75  unset(‪$options['condition'], ‪$options['identifier'], ‪$options['variants']);
76 
77  $this->options = ‪$options;
78  }
79 
84  public function ‪apply(): void
85  {
86  $this->renderable->setOptions($this->options, true);
87  $this->applied = true;
88  }
89 
94  public function ‪conditionMatches(‪Resolver $conditionResolver): bool
95  {
96  if (empty($this->condition)) {
97  return false;
98  }
99 
100  return $conditionResolver->‪evaluate($this->condition);
101  }
102 
106  public function ‪getIdentifier(): string
107  {
108  return ‪$this->identifier;
109  }
110 
114  public function ‪isApplied(): bool
115  {
116  return ‪$this->applied;
117  }
118 }
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$identifier
‪string $identifier
Definition: RenderableVariant.php:31
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\getIdentifier
‪string getIdentifier()
Definition: RenderableVariant.php:101
‪TYPO3\CMS\Form\Domain\Model\Renderable
Definition: AbstractCompositeRenderable.php:3
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:27
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\isApplied
‪bool isApplied()
Definition: RenderableVariant.php:109
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\__construct
‪__construct(string $identifier, array $options, VariableRenderableInterface $renderable)
Definition: RenderableVariant.php:55
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$condition
‪string $condition
Definition: RenderableVariant.php:43
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$applied
‪bool $applied
Definition: RenderableVariant.php:47
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\evaluate
‪bool evaluate(string $condition)
Definition: Resolver.php:72
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$options
‪array $options
Definition: RenderableVariant.php:35
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\conditionMatches
‪bool conditionMatches(Resolver $conditionResolver)
Definition: RenderableVariant.php:89
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant
Definition: RenderableVariant.php:27
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$renderable
‪VariableRenderableInterface $renderable
Definition: RenderableVariant.php:39
‪TYPO3\CMS\Form\Domain\Model\Renderable\VariableRenderableInterface
Definition: VariableRenderableInterface.php:25
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver
Definition: Resolver.php:25
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\apply
‪apply()
Definition: RenderableVariant.php:79
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariantInterface
Definition: RenderableVariantInterface.php:26