‪TYPO3CMS  11.5
RenderableVariant.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
22 
29 {
33  protected ‪$identifier;
34 
38  protected ‪$options;
39 
43  protected ‪$renderable;
44 
48  protected ‪$condition = '';
49 
53  protected ‪$applied = false;
54 
61  public function ‪__construct(
62  string ‪$identifier,
63  array ‪$options,
65  ) {
66  if (‪$identifier === '') {
67  throw new ‪IdentifierNotValidException('The given variant identifier was empty.', 1519998923);
68  }
69  $this->identifier = ‪$identifier;
70  $this->renderable = ‪$renderable;
71 
72  if (isset(‪$options['condition']) && is_string(‪$options['condition'])) {
73  $this->condition = ‪$options['condition'];
74  }
75 
76  unset(‪$options['condition'], ‪$options['identifier'], ‪$options['variants']);
77 
78  $this->options = ‪$options;
79  }
80 
85  public function ‪apply(): void
86  {
87  $this->renderable->setOptions($this->options, true);
88  $this->applied = true;
89  }
90 
95  public function ‪conditionMatches(‪Resolver $conditionResolver): bool
96  {
97  if (empty($this->condition)) {
98  return false;
99  }
100 
101  return $conditionResolver->‪evaluate($this->condition);
102  }
103 
107  public function ‪getIdentifier(): string
108  {
109  return ‪$this->identifier;
110  }
111 
115  public function ‪isApplied(): bool
116  {
117  return ‪$this->applied;
118  }
119 }
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$identifier
‪string $identifier
Definition: RenderableVariant.php:32
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\getIdentifier
‪string getIdentifier()
Definition: RenderableVariant.php:102
‪TYPO3\CMS\Form\Domain\Model\Renderable
Definition: AbstractCompositeRenderable.php:22
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:30
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\isApplied
‪bool isApplied()
Definition: RenderableVariant.php:110
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\__construct
‪__construct(string $identifier, array $options, VariableRenderableInterface $renderable)
Definition: RenderableVariant.php:56
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$condition
‪string $condition
Definition: RenderableVariant.php:44
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$applied
‪bool $applied
Definition: RenderableVariant.php:48
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\evaluate
‪bool evaluate(string $condition)
Definition: Resolver.php:76
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$options
‪array $options
Definition: RenderableVariant.php:36
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\conditionMatches
‪bool conditionMatches(Resolver $conditionResolver)
Definition: RenderableVariant.php:90
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant
Definition: RenderableVariant.php:29
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$renderable
‪VariableRenderableInterface $renderable
Definition: RenderableVariant.php:40
‪TYPO3\CMS\Form\Domain\Model\Renderable\VariableRenderableInterface
Definition: VariableRenderableInterface.php:29
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver
Definition: Resolver.php:28
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\apply
‪apply()
Definition: RenderableVariant.php:80
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariantInterface
Definition: RenderableVariantInterface.php:28