本文整理汇总了PHP中Drupal\node\NodeInterface::url方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::url方法的具体用法?PHP NodeInterface::url怎么用?PHP NodeInterface::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::url方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNodeTeaser
/**
* Tests if file fields in teasers have correct resources.
*
* Ensure that file fields have the correct resource as the object in RDFa
* when displayed as a teaser.
*/
function testNodeTeaser()
{
// Render the teaser.
$node_render_array = entity_view_multiple(array($this->node), 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parses front page where the node is displayed in its teaser form.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
$parser->parse($graph, $html, 'rdfa', $base_uri);
$node_uri = $this->node->url('canonical', ['absolute' => TRUE]);
$file_uri = file_create_url($this->file->getFileUri());
// Node relation to attached file.
$expected_value = array('type' => 'uri', 'value' => $file_uri);
$this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/2000/01/rdf-schema#seeAlso', $expected_value), 'Node to file relation found in RDF output (rdfs:seeAlso).');
$this->drupalGet('node');
}
示例2: testNodeTeaser
/**
* Tests that image fields in teasers have correct resources.
*/
function testNodeTeaser()
{
// Set the display options for the teaser.
$display_options = array('type' => 'image', 'settings' => array('image_style' => 'medium', 'image_link' => 'content'));
$display = entity_get_display('node', 'article', 'teaser');
$display->setComponent($this->fieldName, $display_options)->save();
// Render the teaser.
$node_render_array = node_view($this->node, 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
$parser->parse($graph, $html, 'rdfa', $base_uri);
// Construct the node and image URIs for testing.
$node_uri = $this->node->url('canonical', ['absolute' => TRUE]);
$image_uri = ImageStyle::load('medium')->buildUrl($this->file->getFileUri());
// Test relations from node to image.
$expected_value = array('type' => 'uri', 'value' => $image_uri);
$this->assertTrue($graph->hasProperty($node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).');
// Test image type.
$expected_value = array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/Image');
$this->assertTrue($graph->hasProperty($image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Image type found in RDF output (foaf:Image).');
}
示例3: assertRdfaCommonNodeProperties
/**
* Tests output for properties held in common between articles and pages.
*
* @param \EasyRdf_Graph $graph
* The EasyRDF graph object.
* @param \Drupal\node\NodeInterface $node
* The node being displayed.
* @param string $message_prefix
* The word to use in the test assertion message.
*/
protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $message_prefix)
{
$uri = $node->url('canonical', array('absolute' => TRUE));
// Title.
$expected_value = array('type' => 'literal', 'value' => $node->get('title')->value, 'lang' => 'en');
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/name', $expected_value), "{$message_prefix} title was found (schema:name).");
// Created date.
$expected_value = array('type' => 'literal', 'value' => format_date($node->get('created')->value, 'custom', 'c', 'UTC'), 'lang' => 'en');
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "{$message_prefix} created date was found (schema:dateCreated) in teaser.");
// Body.
$expected_value = array('type' => 'literal', 'value' => $node->get('body')->value, 'lang' => 'en');
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/text', $expected_value), "{$message_prefix} body was found (schema:text) in teaser.");
// Author.
$expected_value = array('type' => 'uri', 'value' => $this->authorUri);
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/author', $expected_value), "{$message_prefix} author was found (schema:author) in teaser.");
// Author type.
$this->assertEqual($graph->type($this->authorUri), 'schema:Person', "{$message_prefix} author type was found (schema:Person).");
// Author name.
$expected_value = array('type' => 'literal', 'value' => $this->adminUser->label());
$this->assertTrue($graph->hasProperty($this->authorUri, 'http://schema.org/name', $expected_value), "{$message_prefix} author name was found (schema:name).");
}