PreprocessBase.php in Express 8
File
themes/contrib/bootstrap/src/Plugin/Preprocess/PreprocessBase.php
View source
<?php
namespace Drupal\bootstrap\Plugin\Preprocess;
use Drupal\bootstrap\Plugin\PluginBase;
use Drupal\bootstrap\Utility\Element;
use Drupal\bootstrap\Utility\Variables;
use Drupal\Core\Template\Attribute;
class PreprocessBase extends PluginBase implements PreprocessInterface {
protected $hook;
protected $info;
protected $variables;
public function preprocess(array &$variables, $hook, array $info) {
$this->hook = $hook;
$this->info = $info;
$this->variables = Variables::create($variables);
if ($this->variables->element) {
if (!$this->variables->element
->hasProperty('has_error')) {
$errors = $this->variables->element
->getProperty('errors');
$this->variables->element
->setProperty('has_error', isset($errors) || $this->variables->element
->getProperty('required') && $this->theme
->getSetting('forms_required_has_error'));
}
$this
->preprocessElement($this->variables->element, $this->variables);
}
$this
->preprocessVariables($this->variables);
}
protected function preprocessAttributes() {
foreach ($this->variables as $name => $value) {
if (strpos($name, 'attributes') !== FALSE && is_array($value)) {
$this->variables[$name] = new Attribute($value);
}
}
}
protected function preprocessDescription() {
if ($this->variables
->offsetGet('description')) {
$description_attributes = $this->variables
->offsetGet('description_attributes', []);
$this->variables
->offsetUnset('description_attributes');
if ($id = $this->variables
->getAttribute('id')) {
$this->variables
->setAttribute('aria-describedby', "{$id}--description");
$description_attributes['id'] = "{$id}--description";
}
$this->variables
->offsetSet('description', [
'attributes' => new Attribute($description_attributes),
'content' => $this->variables['description'],
'position' => $this->variables
->offsetGet('description_display', 'after'),
]);
}
}
protected function preprocessElement(Element $element, Variables $variables) {
}
protected function preprocessVariables(Variables $variables) {
}
}
Classes
Name |
Description |
PreprocessBase |
Base preprocess class used to build the necessary variables for templates. |