‪TYPO3CMS  10.4
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 {
30 
34  protected ‪$identifier;
35 
39  protected ‪$options;
40 
44  protected ‪$renderable;
45 
49  protected ‪$condition = '';
50 
54  protected ‪$applied = false;
55 
62  public function ‪__construct(
63  string ‪$identifier,
64  array ‪$options,
66  ) {
67  if ('' === ‪$identifier) {
68  throw new ‪IdentifierNotValidException('The given variant identifier was empty.', 1519998923);
69  }
70  $this->identifier = ‪$identifier;
71  $this->renderable = ‪$renderable;
72 
73  if (isset(‪$options['condition']) && is_string(‪$options['condition'])) {
74  $this->condition = ‪$options['condition'];
75  }
76 
77  unset(‪$options['condition'], ‪$options['identifier'], ‪$options['variants']);
78 
79  $this->options = ‪$options;
80  }
81 
86  public function ‪apply(): void
87  {
88  $this->renderable->setOptions($this->options, true);
89  $this->applied = true;
90  }
91 
96  public function ‪conditionMatches(‪Resolver $conditionResolver): bool
97  {
98  if (empty($this->condition)) {
99  return false;
100  }
101 
102  return $conditionResolver->‪evaluate($this->condition);
103  }
104 
108  public function ‪getIdentifier(): string
109  {
110  return ‪$this->identifier;
111  }
112 
116  public function ‪isApplied(): bool
117  {
118  return ‪$this->applied;
119  }
120 }
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$identifier
‪string $identifier
Definition: RenderableVariant.php:33
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\getIdentifier
‪string getIdentifier()
Definition: RenderableVariant.php:103
‪TYPO3\CMS\Form\Domain\Model\Renderable
Definition: AbstractCompositeRenderable.php:22
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:31
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\isApplied
‪bool isApplied()
Definition: RenderableVariant.php:111
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\__construct
‪__construct(string $identifier, array $options, VariableRenderableInterface $renderable)
Definition: RenderableVariant.php:57
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$condition
‪string $condition
Definition: RenderableVariant.php:45
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$applied
‪bool $applied
Definition: RenderableVariant.php:49
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\evaluate
‪bool evaluate(string $condition)
Definition: Resolver.php:74
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$options
‪array $options
Definition: RenderableVariant.php:37
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\conditionMatches
‪bool conditionMatches(Resolver $conditionResolver)
Definition: RenderableVariant.php:91
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant
Definition: RenderableVariant.php:29
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$renderable
‪VariableRenderableInterface $renderable
Definition: RenderableVariant.php:41
‪TYPO3\CMS\Form\Domain\Model\Renderable\VariableRenderableInterface
Definition: VariableRenderableInterface.php:29
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver
Definition: Resolver.php:27
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\apply
‪apply()
Definition: RenderableVariant.php:81
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariantInterface
Definition: RenderableVariantInterface.php:28