trait MarkdownStatesTrait in Markdown 3.0.x
Hierarchy
- trait \Drupal\markdown\Traits\MarkdownStatesTrait
2 files declare their use of MarkdownStatesTrait
- BaseExtension.php in src/
Plugin/ Markdown/ Extension/ BaseExtension.php - Markdown.php in src/
Plugin/ Filter/ Markdown.php
File
- src/
Traits/ MarkdownStatesTrait.php, line 5
Namespace
Drupal\markdown\TraitsView source
trait MarkdownStatesTrait {
/**
* Retrieves the ancestry of the extension in a form/render array.
*
* @param array $element
* The element where the #parents array resides.
* @param array $parents
* Optional. Additional parents to add.
* @param string $property
* Optional. The property used to retrieve the array parents.
*
* @return array
* The element's parents array.
*/
protected static function getElementParents(array $element, array $parents = [], string $property = '#array_parents') {
return array_merge($element[$property] ?? [], $parents);
}
/**
* Retrieves a states selector to use based on the form/render array parents.
*
* This is really only useful if using the States API (or something similar)
*
* @param array $parents
* The parents of the element.
* @param string $name
* Optional. The setting name to append to the selector.
*
* @return string
* The selector path of the extension.
*/
protected static function getSatesSelector(array $parents = [], $name = '') {
if (isset($name)) {
$parents[] = $name;
}
$selector = array_shift($parents);
if ($parents) {
$selector .= '[' . implode('][', $parents) . ']';
}
return $selector ? ':input[name="' . $selector . '"]' : '';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MarkdownStatesTrait:: |
protected static | function | Retrieves the ancestry of the extension in a form/render array. | |
MarkdownStatesTrait:: |
protected static | function | Retrieves a states selector to use based on the form/render array parents. |