Commit 85392bfe authored by alexpott's avatar alexpott
Browse files

Issue #2188877 by lokapujya | scor: Support RDFa output in telephone field formatter.

parent 9b87b2b4
<?php
/**
* @file
* Contains \Drupal\rdf\Tests\Field\TelephoneFieldRdfaTest.
*/
namespace Drupal\rdf\Tests\Field;
/**
* Tests the placement of RDFa in telephone field formatters.
*/
class TelephoneFieldRdfaTest extends FieldRdfaTestBase {
/**
* A test value for the telephone field.
*
* @var string
*/
protected $testValue;
/**
* {@inheritdoc}
*/
protected $fieldType = 'telephone';
/**
* {@inheritdoc}
*/
public static $modules = array('telephone', 'text');
public static function getInfo() {
return array(
'name' => 'Field formatter: telephone',
'description' => 'Tests RDFa output by telephone field formatters.',
'group' => 'RDF',
);
}
public function setUp() {
parent::setUp();
$this->createTestField();
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:telephone'),
))->save();
// Set up test values.
$this->testValue = '555-555-5555';
$this->entity = entity_create('entity_test', array());
$this->entity->{$this->fieldName}->value = $this->testValue;
}
/**
* Tests the field formatters.
*/
public function testAllFormatters() {
// Tests the plain formatter.
$this->assertFormatterRdfa(array('type' => 'text_plain'), 'http://schema.org/telephone', array('value' => $this->testValue));
// Tests the telephone link formatter.
$this->assertFormatterRdfa(array('type' => 'telephone_link'), 'http://schema.org/telephone', array('value' => 'tel:' . $this->testValue, 'type' => 'uri'));
$formatter = array(
'type' => 'telephone_link',
'settings' => array('title' => 'Contact us'),
);
$expected_rdf_value = array(
'value' => 'tel:' . $this->testValue,
'type' => 'uri',
);
// Tests the telephone link formatter with custom title.
$this->assertFormatterRdfa($formatter, 'http://schema.org/telephone', $expected_rdf_value);
}
}
......@@ -80,6 +80,14 @@ public function viewElements(FieldItemListInterface $items) {
'#href' => 'tel:' . rawurlencode(preg_replace('/\s+/', '', $item->value)),
'#options' => array('external' => TRUE),
);
if (!empty($item->_attributes)) {
$element[$delta]['#options'] += array('attributes' => array());
$element[$delta]['#options']['attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
}
return $element;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment