"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/Template/AttributeBoolean.php" (26 Nov 2020, 1051 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AttributeBoolean.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\Core\Template;
    4 
    5 use Drupal\Component\Utility\Html;
    6 
    7 /**
    8  * A class that defines a type of boolean HTML attribute.
    9  *
   10  * Boolean HTML attributes are not attributes with values of TRUE/FALSE.
   11  * They are attributes that if they exist in the tag, they are TRUE.
   12  * Examples include selected, disabled, checked, readonly.
   13  *
   14  * To set a boolean attribute on the Attribute class, set it to TRUE.
   15  * @code
   16  *  $attributes = new Attribute();
   17  *  $attributes['disabled'] = TRUE;
   18  *  echo '<select' . $attributes . '/>';
   19  *  // produces <select disabled>;
   20  *  $attributes['disabled'] = FALSE;
   21  *  echo '<select' . $attributes . '/>';
   22  *  // produces <select>;
   23  * @endcode
   24  *
   25  * @see \Drupal\Core\Template\Attribute
   26  */
   27 class AttributeBoolean extends AttributeValueBase {
   28 
   29   /**
   30    * {@inheritdoc}
   31    */
   32   public function render() {
   33     return $this->__toString();
   34   }
   35 
   36   /**
   37    * Implements the magic __toString() method.
   38    */
   39   public function __toString() {
   40     return $this->value === FALSE ? '' : Html::escape($this->name);
   41   }
   42 
   43 }