diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 076cfd3..ac94cab 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Template; - /** * A class that can be used for collecting then rendering HTML attributtes. * @@ -17,7 +16,7 @@ * $attributes = new Attribute(array('id' => 'socks')); * $attributes['class'] = array('black-cat', 'white-cat'); * $attributes['class'][] = 'black-white-cat'; - * echo ''; + * echo ''; * // Produces * @endcode * @@ -26,7 +25,7 @@ * $attributes = new Attribute(array('id' => 'socks')); * $attributes['class'] = array('black-cat', 'white-cat'); * $attributes['class'][] = 'black-white-cat'; - * echo ''; + * echo ''; * // Produces * @endcode */ @@ -64,6 +63,20 @@ public function offsetGet($name) { * Implements ArrayAccess::offsetSet(). */ public function offsetSet($name, $value) { + $value = $this->createAttributeValue($name, $value); + $this->storage[$name] = $value; + } + +/** + * Creates the different types of attribute values. + * @param string $name + * @todo + * @param mixed $value + * @todo + * @return object + * + */ + protected function createAttributeValue($name, $value) { if (is_array($value)) { $value = new AttributeArray($name, $value); } @@ -73,13 +86,7 @@ public function offsetSet($name, $value) { elseif (!is_object($value)) { $value = new AttributeString($name, $value); } - // The $name could be NULL. - if (isset($name)) { - $this->storage[$name] = $value; - } - else { - $this->storage[] = $value; - } + return $value; } /** @@ -105,7 +112,7 @@ public function __toString() { if (!$value->printed()) { $rendered = is_object($value) ? $value->render() : (check_plain($name) . ' = "' . check_plain($value) . '"'); if ($rendered) { - $return .= " $rendered"; + $return .= ' ' . $rendered; } } } @@ -129,12 +136,4 @@ public function __clone() { public function getIterator() { return new \ArrayIterator($this->storage); } - - /** - * Returns the whole array. - */ - public function value() { - return $this->value; - } - } diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index d3521e0..a4d1d12 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -14,13 +14,13 @@ * To use with Attribute, the array must be specified. * Correct: * @code - * $attributes = new Attribute(array()); + * $attributes = new Attribute(); * $attributes['class'] = array(); * $attributes['class'][] = 'cat'; * @endcode * Incorrect: * @code - * $attributes = new Attribute(array()); + * $attributes = new Attribute(); * $attributes['class'][] = 'cat'; * @endcode * @@ -66,7 +66,7 @@ public function offsetExists($offset) { */ public function __toString() { $this->printed = TRUE; - return implode(' ', array_map('check_plain', $this->value)); + return check_plain(implode(' ', $this->value)); } /** diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php index 48ca388..7bfc527 100644 --- a/core/lib/Drupal/Core/Template/AttributeBoolean.php +++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php @@ -16,12 +16,12 @@ * * To set a boolean attribute on the Attribute class, set it to TRUE. * @code - * $attributes = new Attribute(array()); + * $attributes = new Attribute(); * $attributes['disabled'] = TRUE; - * echo '; * $attributes['disabled'] = FALSE; - * echo '; * @endcode * diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index aaea6bb..f63a19a 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -483,12 +483,15 @@ function rdf_preprocess_html(&$variables) { // Adds RDF namespace prefix bindings in the form of an RDFa 1.1 prefix // attribute inside the html element. $prefixes = array(); + // debug($variables['html_attributes']['prefix']); if (!isset($variables['html_attributes']['prefix'])) { $variables['html_attributes']['prefix'] = array(); } foreach(rdf_get_namespaces() as $prefix => $uri) { + // debug($prefix); $variables['html_attributes']['prefix'][] = $prefix . ': ' . $uri . "\n"; } + // debug($variables['html_attributes']['prefix']); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php index 7b5305d..c561529 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php @@ -37,6 +37,10 @@ function testDrupalAttributes() { $this->assertIdentical((string) new Attribute(array('alt' => '')), ' alt=""', 'Empty attribute value #1.'); $this->assertIdentical((string) new Attribute(array('alt' => NULL)), ' alt=""', 'Empty attribute value #2.'); + // Verify boolean attribute values are rendered correctly. + $this->assertIdentical((string) new Attribute(array('disabled' => TRUE)), ' disabled', 'Boolean attribute is rendered.'); + $this->assertIdentical((string) new Attribute(array('disabled' => FALSE)), '', 'Boolean attribute is not rendered.'); + // Verify multiple attributes are rendered. $attributes = array( 'id' => 'id-test',