本文整理汇总了PHP中Drupal\node\NodeInterface::getTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::getTitle方法的具体用法?PHP NodeInterface::getTitle怎么用?PHP NodeInterface::getTitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::getTitle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getDescription
/**
* {@inheritdoc}
*/
public function getDescription()
{
$component_type = $this->node->webform['components'][$this->component['cid']]['type'];
if (webform_component_feature($component_type, 'group')) {
return $this->t('This will immediately delete the %name @type component and all nested components within %name from the %webform webform. This cannot be undone.', ['%name' => $this->node->webform['components'][$this->component['cid']]['name'], '@type' => webform_component_property($component_type, 'label'), '%webform' => $this->node->getTitle()]);
} else {
return $this->t('This will immediately delete the %name component from the %webform webform. This cannot be undone.', ['%name' => $this->node->webform['components'][$this->component['cid']]['name'], '%webform' => $this->node->getTitle()]);
}
}
示例3: testSearchTagsBubbling
/**
* Tests the presence of expected cache tags with referenced entities.
*/
public function testSearchTagsBubbling()
{
// Install field UI and entity reference modules.
$this->container->get('module_installer')->install(['field_ui', 'entity_reference']);
$this->resetAll();
// Creates a new content type that will have an entity reference.
$type_name = 'entity_reference_test';
$type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
$bundle_path = 'admin/structure/types/manage/' . $type->id();
// Create test user.
$admin_user = $this->drupalCreateUser(['access content', 'create ' . $type_name . ' content', 'administer node fields', 'administer node display']);
$this->drupalLogin($admin_user);
// First step: 'Add new field' on the 'Manage fields' page.
$this->drupalGet($bundle_path . '/fields/add-field');
$this->drupalPostForm(NULL, ['label' => 'Test label', 'field_name' => 'test__ref', 'new_storage_type' => 'entity_reference'], t('Save and continue'));
// Second step: 'Field settings' form.
$this->drupalPostForm(NULL, [], t('Save field settings'));
// Create a new node of our newly created node type and fill in the entity
// reference field.
$edit = ['title[0][value]' => 'Llama shop', 'field_test__ref[0][target_id]' => $this->node->getTitle()];
$this->drupalPostForm('node/add/' . $type->id(), $edit, t('Save'));
// Test that the value of the entity reference field is shown.
$this->drupalGet('node/2');
$this->assertText('bike shed shop');
// Refresh the search index.
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
search_update_totals();
// Log in with searching user again.
$this->drupalLogin($this->searchingUser);
// Default search cache tags.
$default_search_tags = ['config:search.page.node_search', 'search_index', 'search_index:node_search', 'rendered', 'node_list'];
// Node search results for shop, should return node:1 (bike shed shop) and
// node:2 (Llama shop). The related authors cache tags should be visible as
// well.
$edit = array();
$edit['keys'] = 'shop';
$this->drupalPostForm('search/node', $edit, t('Search'));
$this->assertText('bike shed shop');
$this->assertText('Llama shop');
$expected_cache_tags = Cache::mergeTags($default_search_tags, ['node:1', 'user:2', 'node:2', 'user:3', 'node_view', 'config:filter.format.plain_text']);
$cache_tags = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertEqual(explode(' ', $cache_tags), $expected_cache_tags);
// Only get the new node in the search results, should result in node:1,
// node:2 and user:3 as cache tags even though only node:1 is shown. This is
// because node:2 is reference in node:1 as an entity reference.
$edit = array();
$edit['keys'] = 'Llama';
$this->drupalPostForm('search/node', $edit, t('Search'));
$this->assertText('Llama shop');
$expected_cache_tags = Cache::mergeTags($default_search_tags, ['node:1', 'node:2', 'user:3', 'node_view']);
$cache_tags = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertEqual(explode(' ', $cache_tags), $expected_cache_tags);
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL)
{
$config = \Drupal::config('simplenews.settings');
// Handling the multi-newsletters options.
$subscriber_count = 0;
$backupsi = array();
foreach ($node->simplenews_issue as $simplenews_issue) {
$backupsi[] = $simplenews_issue->target_id;
}
$subscribers = db_select('simplenews_subscriber__subscriptions', 'r')->fields('r', array('entity_id'))->condition('subscriptions_target_id', $backupsi, 'in')->condition('subscriptions_status', 1)->groupBy('entity_id');
$subscribers->addExpression('count(subscriptions_target_id)', 'entitycount');
$subscriber_count = $subscribers->countQuery()->execute()->fetchField();
$status = $node->simplenews_issue->status;
$form['#title'] = t('<em>Newsletter issue</em> @title', array('@title' => $node->getTitle()));
// We will need the node.
$form_state->set('node', $node);
// Show newsletter sending options if newsletter has not been send yet.
// If send a notification is shown.
if ($status == SIMPLENEWS_STATUS_SEND_NOT) {
$form['test'] = array('#type' => 'details', '#open' => TRUE, '#title' => t('Test'));
$form['test']['test_address'] = array('#type' => 'textfield', '#title' => t('Test email addresses'), '#description' => t('A comma-separated list of email addresses to be used as test addresses.'), '#default_value' => \Drupal::currentUser()->getEmail(), '#size' => 60, '#maxlength' => 128);
$form['test']['submit'] = array('#type' => 'submit', '#value' => t('Send test newsletter issue'), '#name' => 'send_test', '#submit' => array('::submitTestMail'), '#validate' => array('::validateTestAddress'));
$form['send'] = array('#type' => 'details', '#open' => TRUE, '#title' => t('Send'));
$default_handler = isset($form_state->getValue('simplenews')['recipient_handler']) ? $form_state->getValue('simplenews')['recipient_handler'] : $node->simplenews_issue->handler;
$recipient_handler_manager = \Drupal::service('plugin.manager.simplenews_recipient_handler');
$options = $recipient_handler_manager->getOptions();
$form['send']['recipient_handler'] = array('#type' => 'select', '#title' => t('Recipients'), '#description' => t('Please select to configure who to send the email to.'), '#options' => $options, '#default_value' => $default_handler, '#access' => count($options) > 1, '#ajax' => array('callback' => '::ajaxUpdateRecipientHandlerSettings', 'wrapper' => 'recipient-handler-settings', 'method' => 'replace', 'effect' => 'fade'));
// Get the handler class.
$handler_definitions = $recipient_handler_manager->getDefinitions();
$handler = $handler_definitions[$default_handler];
$class = $handler['class'];
$settings = $node->simplenews_issue->handler_settings;
if (method_exists($class, 'settingsForm')) {
$element = array('#parents' => array('simplenews', 'recipient_handler_settings'), '#prefix' => '<div id="recipient-handler-settings">', '#suffix' => '</div>');
$form['send']['recipient_handler_settings'] = $class::settingsForm($element, $settings);
} else {
$form['send']['recipient_handler']['#suffix'] = '<div id="recipient-handler-settings"></div>';
}
// Add some text to describe the send situation.
$form['send']['count'] = array('#type' => 'item', '#markup' => t('Send newsletter issue to @count subscribers.', array('@count' => $subscriber_count)));
if (!$config->get('mail.use_cron')) {
$send_text = t('Mails will be sent immediately.');
} else {
$send_text = t('Mails will be sent when cron runs.');
}
$form['send']['method'] = array('#type' => 'item', '#markup' => $send_text);
if ($node->isPublished()) {
$form['send']['send_now'] = array('#type' => 'submit', '#button_type' => 'primary', '#value' => t('Send now'), '#submit' => array('::submitForm', '::submitSendNow'));
} else {
$form['send']['send_on_publish'] = array('#type' => 'submit', '#button_type' => 'primary', '#value' => t('Send on publish'), '#submit' => array('::submitForm', '::submitSendLater'));
}
} else {
$form['status'] = array('#type' => 'item');
if ($status == SIMPLENEWS_STATUS_SEND_READY) {
$form['status']['#title'] = t('This newsletter issue has been sent to @count subscribers', array('@count' => $node->simplenews_issue->sent_count));
} else {
if ($status == SIMPLENEWS_STATUS_SEND_PUBLISH) {
$form['status']['#title'] = t('The newsletter issue will be sent when the content is published.');
} else {
$form['status']['#title'] = t('This newsletter issue is pending, @count of @total mails already sent.', array('@count' => (int) $node->simplenews_issue->sent_count, '@total' => \Drupal::service('simplenews.spool_storage')->countMails(['entity_type' => 'node', 'entity_id' => $node->id()])));
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['stop'] = array('#type' => 'submit', '#submit' => array('::submitStop'), '#value' => t('Stop sending'));
}
}
return $form;
}
示例5: show
/**
* Show.
*
* @return string
* Return Hello string.
*/
public function show(NodeInterface $node)
{
return ['#type' => 'markup', '#markup' => $this->t('Product title: $title', array('$title' => $node->getTitle()))];
}
示例6: helloWorldNode
/**
* Return the 'Hello World Node' page.
*
* @return string
* A render array containing the title of a node pased has argument.
*/
public function helloWorldNode(NodeInterface $node)
{
$output = array();
$output['hello_world'] = array('#markup' => $node->getTitle());
return $output;
}