‪TYPO3CMS  ‪main
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 
58  public function ‪__construct(
59  string ‪$identifier,
60  array ‪$options,
62  ) {
63  if (‪$identifier === '') {
64  throw new ‪IdentifierNotValidException('The given variant identifier was empty.', 1519998923);
65  }
66  $this->identifier = ‪$identifier;
67  $this->renderable = ‪$renderable;
68 
69  if (isset(‪$options['condition']) && is_string(‪$options['condition'])) {
70  $this->condition = ‪$options['condition'];
71  }
72 
73  unset(‪$options['condition'], ‪$options['identifier'], ‪$options['variants']);
74 
75  $this->options = ‪$options;
76  }
77 
82  public function ‪apply(): void
83  {
84  $this->renderable->setOptions($this->options, true);
85  $this->applied = true;
86  }
87 
88  public function ‪conditionMatches(‪Resolver $conditionResolver): bool
89  {
90  if (empty($this->condition)) {
91  return false;
92  }
93 
94  return (bool)$conditionResolver->‪evaluate($this->condition, ['renderable' => $this->renderable]);
95  }
96 
97  public function ‪getIdentifier(): string
98  {
99  return ‪$this->identifier;
100  }
101 
102  public function ‪isApplied(): bool
103  {
104  return ‪$this->applied;
105  }
106 }
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\$identifier
‪string $identifier
Definition: RenderableVariant.php:32
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\conditionMatches
‪conditionMatches(Resolver $conditionResolver)
Definition: RenderableVariant.php:83
‪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\__construct
‪__construct(string $identifier, array $options, VariableRenderableInterface $renderable)
Definition: RenderableVariant.php:53
‪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\Form\Domain\Model\Renderable\RenderableVariant\$options
‪array $options
Definition: RenderableVariant.php:36
‪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:32
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\evaluate
‪evaluate(string $expression, array $contextVariables=[])
Definition: Resolver.php:71
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\apply
‪apply()
Definition: RenderableVariant.php:77
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\isApplied
‪isApplied()
Definition: RenderableVariant.php:97
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant\getIdentifier
‪getIdentifier()
Definition: RenderableVariant.php:92
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariantInterface
Definition: RenderableVariantInterface.php:28