本文整理汇总了PHP中Drupal\node\NodeInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::get方法的具体用法?PHP NodeInterface::get怎么用?PHP NodeInterface::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewQuestion
/**
* Helper function to setup the faq question.
*
* @param array &$data
* Array reference to store display data in.
* @param \Drupal\node\NodeInterface $node
* The node object.
* @param string $path
* The path/url which the question should link to if links are disabled.
* @param string $anchor
* Link anchor to use in question links.
*/
public static function viewQuestion(&$data, \Drupal\node\NodeInterface $node, $path = NULL, $anchor = NULL)
{
$faq_settings = \Drupal::config('faq.settings');
$disable_node_links = $faq_settings->get('disable_node_links');
$question = '';
// Don't link to faq node, instead provide no link, or link to current page.
if ($disable_node_links) {
if (empty($path) && empty($anchor)) {
$question = $node->getTitle();
} elseif (empty($path)) {
// Can't seem to use l() function with empty string as screen-readers
// don't like it, so create anchor name manually.
$question = '<a id="' . $anchor . '"></a>' . $node->getTitle();
} else {
$options = array();
if ($anchor) {
$options['attributes'] = array('id' => $anchor);
}
$question = l($node->getTitle(), $path, $options);
}
} else {
$node_id = $node->id();
if (empty($anchor)) {
$question = l($node->getTitle(), "node/{$node_id})");
} else {
$question = l($node->getTitle(), "node/{$node_id}", array("attributes" => array("id" => "{$anchor}")));
}
}
$question = '<span datatype="" property="dc:title">' . $question . '</span>';
$detailed_question = $node->get('field_detailed_question')->value;
if ($faq_settings->get('display') != 'hide_answer' && !empty($detailed_question) && $faq_settings->get('question_length') == 'both') {
$question .= '<div class="faq-detailed-question">' . $detailed_question . '</div>';
}
$data['question'] = SafeMarkup::set($question);
}
示例2: testCommentNodeCommentStatistics
/**
* Tests the node comment statistics.
*/
function testCommentNodeCommentStatistics()
{
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$this->drupalGet('<front>');
$this->assertNoLink(t('1 comment'));
$this->assertEqual($this->node->get('comment')->comment_count, 0, 'The number of comments for the node is correct (0 comments)');
// Test comment statistic when creating comments.
$comment1 = Comment::create(['entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'How much wood would a woodchuck chuck', 'comment_body' => $this->randomMachineName(128), 'entity_id' => $this->node->id()]);
$comment1->save();
$node_storage->resetCache([$this->node->id()]);
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->comment_count, 1, 'The number of comments for the node is correct (1 comment)');
$this->drupalGet('<front>');
$this->assertLink(t('1 comment'));
$comment2 = Comment::create(['entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'A big black bug bit a big black dog', 'comment_body' => $this->randomMachineName(128), 'entity_id' => $this->node->id()]);
$comment2->save();
$comment3 = Comment::create(['entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'How much pot, could a pot roast roast', 'comment_body' => $this->randomMachineName(128), 'entity_id' => $this->node->id()]);
$comment3->save();
$node_storage->resetCache([$this->node->id()]);
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->comment_count, 3, 'The number of comments for the node is correct (3 comments)');
$this->drupalGet('<front>');
$this->assertLink(t('3 comments'));
// Test comment statistic when deleting comments.
$comment1->delete();
$comment2->delete();
$node_storage->resetCache([$this->node->id()]);
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->comment_count, 1, 'The number of comments for the node is correct (1 comment)');
$this->drupalGet('<front>');
$this->assertLink(t('1 comment'));
$comment3->delete();
$node_storage->resetCache([$this->node->id()]);
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->comment_count, 0, 'The number of comments for the node is correct (0 comments)');
$this->drupalGet('<front>');
$this->assertNoLink(t('1 comment'));
$this->assertNoLink(t('comments'));
}
示例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).");
}
示例4: prepareRevertedRevision
/**
* Prepares a revision to be reverted.
*
* @param \Drupal\node\NodeInterface $revision
* The revision to be reverted.
* The type of $revision should be
* \Drupal\Core\Entity\ContentEntityInterface. But at the moment we need to
* stay compatible with
* \Drupal\node\Form\NodeRevisionRevertForm::prepareRevertedRevision(). See
* https://www.drupal.org/node/2350939
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\node\NodeInterface
* The prepared revision ready to be stored.
*/
protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) {
foreach ($revision->getFieldDefinitions() as $field_name => $definition) {
if ($form_state->getValue('revert_' . $field_name)) {
$this->latestRevision->set($field_name, $revision->get($field_name)->getValue());
}
}
$this->latestRevision->setNewRevision();
$this->latestRevision->isDefaultRevision(TRUE);
return $this->latestRevision;
}