本文整理汇总了PHP中Drupal\node\NodeInterface::id方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::id方法的具体用法?PHP NodeInterface::id怎么用?PHP NodeInterface::id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBasicSettings
/**
* Test the basic settings.
*/
public function testBasicSettings() {
$manage_display = '/admin/structure/types/manage/article/display';
$this->drupalGet($manage_display);
$this->drupalPostAjaxForm(NULL, [], 'body_settings_edit');
$this->drupalPostAjaxForm(NULL, [
'fields[body][label]' => 'above',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_tag]' => 'article',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_classes]' => 'my-field-class',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_item_tag]' => 'code',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_item_classes]' => 'my-field-item-class',
'fields[body][settings_edit_form][third_party_settings][fences][fences_label_tag]' => 'h2',
'fields[body][settings_edit_form][third_party_settings][fences][fences_label_classes]' => 'my-label-class',
], ['body_plugin_settings_update' => 'Update']);
$this->drupalPostForm(NULL, [], 'Save');
$expected_field_markup = <<<EOD
<article class="my-field-class clearfix text-formatted field field--name-body field--type-text-with-summary field--label-above field__items">
<h2 class="my-label-class field__label">Body</h2>
<code class="my-field-item-class field__item">
<p>Body field value.</p>
</code>
</article>
EOD;
$page = $this->drupalGet('/node/' . $this->node->id());
$this->assertTrue(strpos($this->stripWhitespace($page), $this->stripWhitespace($expected_field_markup)) !== FALSE, 'Found the correct field markup on the page.');
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL)
{
$this->attributeTable = 'uc_product_attributes';
$this->optionTable = 'uc_product_options';
$this->idField = 'nid';
$this->idValue = $node->id();
$attributes = uc_product_get_attributes($node->id());
return parent::buildForm($form, $form_state, $attributes);
}
示例3: readNode
/**
* Marks a node as read by the current user right now.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request of the page.
* @param \Drupal\node\NodeInterface $node
* The node whose "last read" timestamp should be updated.
*/
public function readNode(Request $request, NodeInterface $node)
{
if ($this->currentUser()->isAnonymous()) {
throw new AccessDeniedHttpException();
}
// Update the history table, stating that this user viewed this node.
history_write($node->id());
return new JsonResponse((int) history_read($node->id()));
}
示例4: schedule
/**
* Simulates the scheduled (un)publication of a node.
*
* @param \Drupal\node\NodeInterface $node
* The node to schedule.
* @param string $action
* The action to perform: either 'publish' or 'unpublish'. Defaults to
* 'publish'.
*
* @return \Drupal\node\NodeInterface
* The updated node, after scheduled (un)publication via a cron run.
*/
protected function schedule(NodeInterface $node, $action = 'publish')
{
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Simulate scheduling by setting the (un)publication date in the past and
// running cron.
$node->{$action . '_on'} = strtotime('-1 day');
$node->save();
scheduler_cron();
$node_storage->resetCache(array($node->id()));
return $node_storage->load($node->id());
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL)
{
$query = \Drupal::request()->query->all();
$form['#action'] = Url::fromRoute('<current>')->setOptions(['query' => $query])->toString();
$form['nid'] = array('#type' => 'value', '#value' => $node->id());
$form['qty'] = array('#type' => 'value', '#value' => 1);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Add to cart'), '#id' => 'edit-submit-' . $node->id());
uc_form_alter($form, $form_state, $this->getFormId());
return $form;
}
示例6: featuresOverview
/**
* Displays the product features tab on a product node edit form.
*/
public function featuresOverview(NodeInterface $node)
{
$header = array($this->t('Type'), $this->t('Description'), $this->t('Operations'));
$rows = [];
$features = uc_product_feature_load_multiple($node->id());
foreach ($features as $feature) {
$operations = array('edit' => array('title' => $this->t('Edit'), 'url' => Url::fromRoute('uc_product.feature_edit', ['node' => $node->id(), 'fid' => $feature->fid, 'pfid' => $feature->pfid])), 'delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_product.feature_delete', ['node' => $node->id(), 'fid' => $feature->fid, 'pfid' => $feature->pfid])));
$rows[] = array(array('data' => uc_product_feature_data($feature->fid, 'title')), array('data' => array('#markup' => $feature->description)), array('data' => array('#type' => 'operations', '#links' => $operations)));
}
$build['features'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('class' => array('uc-product-features')), '#empty' => $this->t('No features found for this product.'));
$build['add_form'] = $this->formBuilder()->getForm('Drupal\\uc_product\\Form\\ProductFeatureAddForm', $node);
return $build;
}
示例7: setUp
protected function setUp()
{
parent::setUp();
ViewTestData::createTestViews(get_class($this), array('tracker_test_views'));
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
// Add a comment field.
$this->addDefaultCommentField('node', 'page');
$permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval');
$account = $this->drupalCreateUser($permissions);
$this->drupalLogin($account);
$this->node = $this->drupalCreateNode(array('title' => $this->randomMachineName(8), 'uid' => $account->id(), 'status' => 1));
$this->comment = Comment::create(array('entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'subject' => $this->randomMachineName(), 'comment_body[' . LanguageInterface::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomMachineName(20)));
}
示例8: 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);
}
示例9: testExpiredLogs
/**
* Tests that cron clears day counts and expired access logs.
*/
function testExpiredLogs()
{
$this->config('statistics.settings')->set('count_content_views', 1)->save();
\Drupal::state()->set('statistics.day_timestamp', 8640000);
$this->drupalGet('node/' . $this->testNode->id());
// Manually calling statistics.php, simulating ajax behavior.
$nid = $this->testNode->id();
$post = array('nid' => $nid);
global $base_url;
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
$this->client->post($stats_path, array('body' => $post));
$this->drupalGet('node/' . $this->testNode->id());
$this->client->post($stats_path, array('body' => $post));
$this->assertText('1 view', 'Node is viewed once.');
// statistics_cron() will subtract
// statistics.settings:accesslog.max_lifetime config from REQUEST_TIME in
// the delete query, so wait two secs here to make sure the access log will
// be flushed for the node just hit.
sleep(2);
$this->cronRun();
$this->drupalGet('admin/reports/pages');
$this->assertNoText('node/' . $this->testNode->id(), 'No hit URL found.');
$result = db_select('node_counter', 'nc')->fields('nc', array('daycount'))->condition('nid', $this->testNode->id(), '=')->execute()->fetchField();
$this->assertFalse($result, 'Daycounter is zero.');
}
示例10: testRetain
/**
* Tests retaining of node form submissions containing profanity.
*/
function testRetain()
{
$this->drupalLogin($this->adminUser);
$this->setProtectionUI('node_article_form', FormInterface::MOLLOM_MODE_ANALYSIS, NULL, ['checks[profanity]' => TRUE, 'discard' => 0]);
$this->drupalLogout();
// Login and submit a node.
$this->drupalLogin($this->webUser);
$this->drupalGet('node/add/article');
$edit = ['title[0][value]' => 'profanity', 'body[0][value]' => 'ham profanity'];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
debug($this->node, 'node');
$this->assertFalse($this->node->isPublished(), t('Node containing profanity was retained as unpublished.'));
$this->assertUrl('node/' . $this->node->id());
$this->assertMollomData('node', $this->node->id());
}
示例11: setUp
protected function setUp()
{
parent::setUp();
ViewTestData::createTestViews(get_class($this), array('comment_test_views'));
// Add two users, create a node with the user1 as author and another node
// with user2 as author. For the second node add a comment from user1.
$this->account = $this->drupalCreateUser(array('skip comment approval'));
$this->account2 = $this->drupalCreateUser();
$this->drupalLogin($this->account);
$this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
$this->addDefaultCommentField('node', 'page');
$this->nodeUserPosted = $this->drupalCreateNode();
$this->nodeUserCommented = $this->drupalCreateNode(array('uid' => $this->account2->id()));
$comment = array('uid' => $this->loggedInUser->id(), 'entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'How much wood would a woodchuck chuck', 'cid' => '', 'pid' => '', 'mail' => 'someone@example.com');
$this->comment = Comment::create($comment);
$this->comment->save();
}
示例12: 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_render($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 = url('<front>', array('absolute' => TRUE));
$parser->parse($graph, $html, 'rdfa', $base_uri);
$node_uri = url('node/' . $this->node->id(), array('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');
}
示例13: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
if ($this->bookManager->checkNodeIsRemovable($this->node)) {
$this->bookManager->deleteFromBook($this->node->id());
drupal_set_message($this->t('The post has been removed from the book.'));
}
$form_state['redirect_route'] = $this->getCancelRoute();
}
示例14: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if ($this->bookManager->checkNodeIsRemovable($this->node)) {
$this->bookManager->deleteFromBook($this->node->id());
drupal_set_message($this->t('The post has been removed from the book.'));
}
$form_state->setRedirectUrl($this->getCancelUrl());
}
示例15: testAutocompleteQuickEdit
/**
* Tests Quick Edit autocomplete term behavior.
*/
public function testAutocompleteQuickEdit()
{
$this->drupalLogin($this->editor_user);
$quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->field_name . '/und/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for
// handling pages with JSON responses, so we need our own solution here.
$form_tokens_found = preg_match('/\\sname="form_token" value="([^"]+)"/', $ajax_commands[0]['data'], $token_match) && preg_match('/\\sname="form_build_id" value="([^"]+)"/', $ajax_commands[0]['data'], $build_id_match);
$this->assertTrue($form_tokens_found, 'Form tokens found in output.');
if ($form_tokens_found) {
$post = array('form_id' => 'quickedit_field_form', 'form_token' => $token_match[1], 'form_build_id' => $build_id_match[1], $this->field_name => implode(', ', array($this->term1->getName(), 'new term', $this->term2->getName())), 'op' => t('Save'));
// Submit field form and check response. Should render back all the terms.
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->drupalSetContent($ajax_commands[0]['data']);
$this->assertLink($this->term1->getName());
$this->assertLink($this->term2->getName());
$this->assertText('new term');
$this->assertNoLink('new term');
// Load the form again, which should now get it back from TempStore.
$quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->field_name . '/und/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$ajax_commands = Json::decode($response);
// The AjaxResponse's first command is an InsertCommand which contains
// the form to edit the taxonomy term field, it should contain all three
// taxonomy terms, including the one that has just been newly created and
// which is not yet stored.
$this->drupalSetContent($ajax_commands[0]['data']);
$this->assertFieldByName($this->field_name, implode(', ', array($this->term1->getName(), 'new term', $this->term2->label())));
// Save the entity.
$post = array('nocssjs' => 'true');
$response = $this->drupalPost('quickedit/entity/node/' . $this->node->id(), 'application/json', $post);
$this->assertResponse(200);
// The full node display should now link to all entities, with the new
// one created in the database as well.
$this->drupalGet('node/' . $this->node->id());
$this->assertLink($this->term1->getName());
$this->assertLink($this->term2->getName());
$this->assertLink('new term');
}
}