final class TokenType in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/core_event_dispatcher/src/ValueObject/TokenType.php \Drupal\core_event_dispatcher\ValueObject\TokenType
Token ValueObject.
Convenience object to handle the integrity and assembly of token types.
Hierarchy
- class \Drupal\core_event_dispatcher\ValueObject\TokenType
Expanded class hierarchy of TokenType
4 files declare their use of TokenType
- ExampleTokenEventSubscriber.php in examples/
ExampleTokenEventSubscriber.php - TokenEventTest.php in modules/
core_event_dispatcher/ tests/ src/ Unit/ Token/ TokenEventTest.php - TokensInfoEvent.php in modules/
core_event_dispatcher/ src/ Event/ Token/ TokensInfoEvent.php - TokenTypeTest.php in modules/
core_event_dispatcher/ tests/ src/ Unit/ Token/ TokenTypeTest.php
File
- modules/
core_event_dispatcher/ src/ ValueObject/ TokenType.php, line 14
Namespace
Drupal\core_event_dispatcher\ValueObjectView source
final class TokenType {
/**
* Type.
*
* @var string
*/
private $type;
/**
* Name.
*
* @var string
*/
private $name;
/**
* Description.
*
* @var string|\Drupal\Component\Render\MarkupInterface
*/
private $description;
/**
* Needs data.
*
* @var string
*/
private $needsData;
/**
* Use create function instead.
*/
private function __construct() {
}
/**
* Token type factory.
*
* @param string $type
* The group name, like 'node'.
* @param string|\Drupal\Component\Render\MarkupInterface $name
* The print-able name of the type.
*
* @return self
* A new instance.
*
* @throws \UnexpectedValueException
*/
public static function create(string $type, $name) : self {
$instance = new self();
if (!is_string($name) && !$name instanceof MarkupInterface) {
throw new UnexpectedValueException('Name should be a string or an instance of MarkupInterface');
}
$instance->type = $type;
$instance->name = $name;
return $instance;
}
/**
* Set description and return a new instance.
*
* @param string|\Drupal\Component\Render\MarkupInterface $description
* The description of the token type.
*
* @return self
* A new instance with the description.
*
* @throws \UnexpectedValueException
*/
public function setDescription($description) : self {
if (!is_string($description) && !$description instanceof MarkupInterface) {
throw new UnexpectedValueException('Description should be a string or an instance of MarkupInterface');
}
$clone = clone $this;
$clone->description = $description;
return $clone;
}
/**
* Set the needs data and return a new instance.
*
* @param string $needsData
* The needs data.
*
* @return self
* A new instance with the needs data property.
*/
public function setNeedsData(string $needsData) : self {
$clone = clone $this;
$clone->needsData = $needsData;
return $clone;
}
/**
* Getter.
*
* @return string|\Drupal\Component\Render\MarkupInterface|null
* The description.
*/
public function getDescription() {
return $this->description;
}
/**
* Getter.
*
* @return string|null
* The needs data property.
*/
public function getNeedsData() : ?string {
return $this->needsData;
}
/**
* Getter.
*
* @return string
* The token type like 'node'.
*/
public function getType() : string {
return $this->type;
}
/**
* Getter.
*
* @return string
* The token type label, like 'The Node type'.
*/
public function getName() : string {
return $this->name;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TokenType:: |
private | property | Description. | |
TokenType:: |
private | property | Name. | |
TokenType:: |
private | property | Needs data. | |
TokenType:: |
private | property | Type. | |
TokenType:: |
public static | function | Token type factory. | |
TokenType:: |
public | function | Getter. | |
TokenType:: |
public | function | Getter. | |
TokenType:: |
public | function | Getter. | |
TokenType:: |
public | function | Getter. | |
TokenType:: |
public | function | Set description and return a new instance. | |
TokenType:: |
public | function | Set the needs data and return a new instance. | |
TokenType:: |
private | function | Use create function instead. |