Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function preprocessVariables(Variables $variables, $hook, array $info)
 {
     // Retrieve the ID, generating one if needed.
     $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-panel')));
     unset($variables['id']);
     // Handle collapsible state.
     if ($variables['heading'] && $variables['collapsible']) {
         // Retrieve the body ID attribute.
         if ($body_id = $variables->getAttribute('id', "{$id}--content", 'body_attributes')) {
             // Ensure the target is set.
             if ($variables['target'] = $variables->offsetGet('target', "#{$body_id}")) {
                 // Set additional necessary attributes to the heading.
                 $variables->setAttributes(['aria-controls' => preg_replace('/^#/', '', $variables['target']), 'aria-expanded' => !$variables['collapsed'] ? 'true' : 'false', 'aria-pressed' => !$variables['collapsed'] ? 'true' : 'false', 'data-toggle' => 'collapse', 'role' => 'button'], 'heading_attributes');
             }
         }
     }
     // Ensure there is a valid panel state.
     if (!$variables->offsetGet('panel_type')) {
         $variables->offsetSet('panel_type', 'default');
     }
     // Convert the description variable.
     $this->preprocessDescription($variables, $hook, $info);
     // Ensure all attributes are proper objects.
     $this->preprocessAttributes($variables, $hook, $info);
 }