AttributeString example

public function testIterate() {
    $attribute = new Attribute(['class' => ['example-class'], 'id' => 'example-id']);

    $counter = 0;
    foreach ($attribute as $key => $value) {
      if ($counter == 0) {
        $this->assertEquals('class', $key);
        $this->assertEquals(new AttributeArray('class', ['example-class'])$value);
      }
      if ($counter == 1) {
        $this->assertEquals('id', $key);
        $this->assertEquals(new AttributeString('id', 'example-id')$value);
      }
      $counter++;
    }
  }

  /** * Tests printing of an attribute. */
  public function testPrint() {
    $attribute = new Attribute(['class' => ['example-class'], 'id' => 'example-id', 'enabled' => TRUE]);

    
      // in core or cast them.       $value = new AttributeArray($name$value);
    }
    elseif (is_bool($value)) {
      $value = new AttributeBoolean($name$value);
    }
    // As a development aid, we allow the value to be a safe string object.     elseif ($value instanceof MarkupInterface) {
      // Attributes are not supposed to display HTML markup, so we just convert       // the value to plain text.       $value = PlainTextOutput::renderFromHtml($value);
      $value = new AttributeString($name$value);
    }
    elseif (!is_object($value)) {
      $value = new AttributeString($name$value);
    }
    return $value;
  }

  /** * {@inheritdoc} */
  #[\ReturnTypeWillChange]
Home | Imprint | This part of the site doesn't use cookies.