當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Node::id方法代碼示例

本文整理匯總了PHP中Drupal\node\Entity\Node::id方法的典型用法代碼示例。如果您正苦於以下問題:PHP Node::id方法的具體用法?PHP Node::id怎麽用?PHP Node::id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\node\Entity\Node的用法示例。


在下文中一共展示了Node::id方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testNodeCounterIntegration

 /**
  * Tests the integration of the {node_counter} table in views.
  */
 public function testNodeCounterIntegration()
 {
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node/' . $this->node->id());
     // Manually calling statistics.php, simulating ajax behavior.
     // @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging().
     global $base_url;
     $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
     $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl', array(CURLOPT_TIMEOUT => 10)]);
     $client->post($stats_path, array('form_params' => array('nid' => $this->node->id())));
     $this->drupalGet('test_statistics_integration');
     $expected = statistics_get($this->node->id());
     // Convert the timestamp to year, to match the expected output of the date
     // handler.
     $expected['timestamp'] = date('Y', $expected['timestamp']);
     foreach ($expected as $field => $value) {
         $xpath = "//div[contains(@class, views-field-{$field})]/span[@class = 'field-content']";
         $this->assertFieldByXpath($xpath, $value, "The {$field} output matches the expected.");
     }
     $this->drupalLogout();
     $this->drupalLogin($this->deniedUser);
     $this->drupalGet('test_statistics_integration');
     $this->assertResponse(200);
     foreach ($expected as $field => $value) {
         $xpath = "//div[contains(@class, views-field-{$field})]/span[@class = 'field-content']";
         $this->assertNoFieldByXpath($xpath, $value, "The {$field} output is not displayed.");
     }
 }
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:31,代碼來源:IntegrationTest.php

示例2: testFieldAccess

 /**
  * Test that hook_entity_field_access() is called.
  */
 function testFieldAccess()
 {
     // Assert the text is visible.
     $this->drupalGet('node/' . $this->node->id());
     $this->assertText($this->testViewFieldValue);
     // Assert the text is not visible for anonymous users.
     // The field_test module implements hook_entity_field_access() which will
     // specifically target the 'test_view_field' field.
     $this->drupalLogout();
     $this->drupalGet('node/' . $this->node->id());
     $this->assertNoText($this->testViewFieldValue);
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:15,代碼來源:FieldAccessTest.php

示例3: doFlagReset

  /**
   * Reset the flag and ensure the flaggings are deleted.
   */
  public function doFlagReset() {
    // Flag the node.
    $this->flagService->flag($this->flag, $this->node, $this->adminUser);

    $ids_before = $this->entityQueryManager->get('flagging')
      ->condition('flag_id', $this->flag->id())
      ->condition('entity_type', 'node')
      ->condition('entity_id', $this->node->id())
      ->execute();

    $this->assertEqual(count($ids_before), 1, "The flag has one flagging.");

    // Go to the reset form for the flag.
    $this->drupalGet('admin/structure/flags/manage/' . $this->flag->id() . '/reset');

    $this->assertText($this->t('Are you sure you want to reset the Flag'));

    $this->drupalPostForm(NULL, [], $this->t('Reset'));

    $ids_after = $this->entityQueryManager->get('flagging')
      ->condition('flag_id', $this->flag->id())
      ->condition('entity_type', 'node')
      ->condition('entity_id', $this->node->id())
      ->execute();

    $this->assertEqual(count($ids_after), 0, "The flag has no flaggings after being reset.");
  }
開發者ID:AshishNaik021,項目名稱:iimisac-d8,代碼行數:30,代碼來源:AdminUITest.php

示例4: mapAnalysisIssues

 public function mapAnalysisIssues(Node $entity, array $results)
 {
     $nid = $entity->id();
     foreach ($results as $issue_entity) {
         /** @var EntityInterface $issue_entity */
         $this->connection->insert('code_analyzer_project_issues')->fields(array('nid' => $nid, 'inid' => $issue_entity->id()))->execute();
     }
 }
開發者ID:malcomio,項目名稱:drupalytics,代碼行數:8,代碼來源:IssueMapper.php

示例5: createReferrerEntity

 /**
  * Create the referrer entity.
  */
 protected function createReferrerEntity()
 {
     /** @var \Drupal\node\Entity\Node $node */
     $node = entity_create($this->testEntityTypeName, array('title' => $this->randomMachineName(), 'type' => $this->referrerType->id(), 'description' => array('value' => $this->randomMachineName(), 'format' => 'basic_html'), $this->referenceFieldName => array(array('target_id' => $this->referencedEntityWithTranslation->id()), array('target_id' => $this->referencedEntityWithoutTranslation->id())), 'langcode' => $this->baseLangcode));
     $node->save();
     $node->addTranslation($this->translateToLangcode, $node->toArray());
     $node->save();
     return $node;
 }
開發者ID:komejo,項目名稱:article-test,代碼行數:12,代碼來源:EntityReferenceFieldTranslatedReferenceViewTest.php

示例6: testTranslatedTaxonomyTermReferenceDisplay

 /**
  * Tests if the translated taxonomy term is displayed.
  */
 public function testTranslatedTaxonomyTermReferenceDisplay()
 {
     $path = 'node/' . $this->node->id();
     $translation_path = $this->translateToLangcode . '/' . $path;
     $this->drupalGet($path);
     $this->assertNoText($this->translatedTagName);
     $this->assertText($this->baseTagName);
     $this->drupalGet($translation_path);
     $this->assertText($this->translatedTagName);
     $this->assertNoText($this->baseTagName);
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:14,代碼來源:TermTranslationFieldViewTest.php

示例7: testEntityPrintAccess

 /**
  * Test the access works for viewing the PDF's.
  */
 public function testEntityPrintAccess()
 {
     // User with entity print access but not content access.
     $account = $this->drupalCreateUser(['entity print access'], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(403, 'User with only the entity print access permission cannot view PDF.');
     // User with access content but not entity print access.
     $account = $this->drupalCreateUser(['access content'], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(403, 'User with access content but no entity print permission cannot view PDF.');
     // User with both entity print and entity view.
     $account = $this->drupalCreateUser(['entity print access', 'access content'], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(200, 'User with both permissions can view the PDF.');
     // User with neither permissions.
     $account = $this->drupalCreateUser([], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(403, 'User with neither permission cannot view the PDF.');
 }
開發者ID:gerbreown1,項目名稱:calvaryfree,代碼行數:26,代碼來源:EntityPrintTest.php

示例8: testReportNode

 /**
  * Tests appearance of feedback options on node delete forms.
  */
 function testReportNode()
 {
     // Create a second node type, which is not protected.
     $this->drupalCreateContentType(array('type' => 'unprotected', 'name' => 'Unprotected'));
     user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['create unprotected content', 'delete own unprotected content', 'delete own article content']);
     // Protect the article node type.
     $this->drupalLogin($this->adminUser);
     $this->setProtectionUI('node_article_form');
     $this->drupalLogout();
     // Login and submit a protected article node.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node/add/article');
     $edit = array('title[0][value]' => 'protected ham', 'body[0][value]' => 'ham');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertUrl('node/' . $this->node->id());
     $this->assertMollomData('node', $this->node->id());
     // Verify that no feedback options appear on the delete confirmation form
     // for the node author.
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertNoText(t('Report as…'));
     // Verify that feedback options appear for the admin user.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertText(t('Report as…'));
     // Login and submit an unprotected node.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node/add/unprotected');
     $edit = array('title[0][value]' => 'unprotected spam', 'body[0][value]' => 'spam');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertUrl('node/' . $this->node->id());
     $this->assertNoMollomData('node', $this->node->id());
     // Verify that no feedback options appear on the delete confirmation form
     // for the node author.
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertNoText(t('Report as…'));
     // Verify that no feedback options appear for the admin user.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertNoText(t('Report as…'));
 }
開發者ID:isramv,項目名稱:camp-gdl,代碼行數:49,代碼來源:ReportingTest.php

示例9: buildForm

 public function buildForm(array $form, FormStateInterface $form_state, Node $node = NULL)
 {
     $form['#node'] = $node;
     $config = $this->getConfiguration();
     $form['nid'] = array('#type' => 'value', '#value' => $node->id());
     $form['cid'] = array('#type' => 'value', '#value' => $config['cid']);
     $form['#component'] = $this;
     // Load basic component information from query string
     $form['type'] = array('#type' => 'value', '#value' => $config['type']);
     $form['pid'] = array('#type' => 'value', '#value' => $config['pid']);
     $form['weight'] = array('#type' => 'value', '#value' => $config['weight']);
     $form['name'] = ['#type' => 'textfield', '#title' => t('Name'), '#description' => t('This is used as a descriptive label when displaying this form element.'), '#size' => 60, '#maxlength' => NULL, '#required' => TRUE, '#default_value' => $config['name'], '#weight' => -20, '#attributes' => ['required' => TRUE, 'class' => ['webform-component-name']]];
     $form['form_key'] = ['#type' => 'machine_name', '#title' => t('Field key'), '#description' => t('Enter a machine readable key for this form element. May contain only alphanumeric characters and underscores. This key will be used as the name attribute of the form element. This value has no effect on the way data is saved, but may be helpful if doing custom form processing.'), '#size' => 60, '#machine_name' => ['exists' => array($this, 'componentKeyExists'), 'source' => array('name')], '#maxlength' => NULL, '#required' => TRUE, '#weight' => -19, '#attributes' => ['required' => TRUE, 'class' => ['webform-component-form-key']]];
     $form['validation'] = ['#type' => 'details', '#title' => t('Validation'), '#collapsible' => TRUE, '#open' => TRUE, '#attributes' => ['class' => ['webform-component-validation']]];
     $form['validation']['required'] = ['#type' => 'checkbox', '#title' => t('Required'), '#description' => t('Check this option if the user must enter a value.'), '#default_value' => $config['required'], '#attributes' => ['class' => ['webform-component-required']]];
     if ($this->supports_unique) {
         $form['validation']['unique'] = array('#type' => 'checkbox', '#title' => t('Unique'), '#return_value' => 1, '#description' => t('Check that all entered values for this field are unique. The same value is not allowed to be used twice.'), '#weight' => 1, '#default_value' => $config['extra']['unique'], '#parents' => array('extra', 'unique'));
     }
     $form['display'] = ['#type' => 'details', '#title' => t('Display'), '#collapsible' => TRUE, '#open' => TRUE, '#attributes' => ['class' => ['webform-component-display']]];
     $form['display']['wrapper_css'] = ['#type' => 'textfield', '#title' => t('Wrapper CSS classes'), '#description' => t('Apply a class to the wrapper around both the field and its label. Separate multiple classes by spaces.'), '#size' => 60, '#maxlength' => NULL, '#weight' => 20, '#parents' => array('extra', 'wrapper_css'), '#attributes' => ['class' => ['webform-component-wrapper-css']]];
     $form['display']['field_css'] = ['#type' => 'textfield', '#title' => t('Field CSS classes'), '#description' => t('Apply a class to the field. Separate multiple by spaces.'), '#size' => 60, '#maxlength' => NULL, '#weight' => 22, '#parents' => array('extra', 'field_css'), '#attributes' => ['class' => ['webform-component-field-css']]];
     if ($this->supports_disabled) {
         $form['display']['disabled'] = array('#type' => 'checkbox', '#title' => t('Disabled'), '#return_value' => 1, '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'), '#weight' => 11, '#default_value' => $config['extra']['disabled'], '#parents' => array('extra', 'disabled'));
     }
     if ($this->supports_prefix_suffix) {
         $form['display']['field_prefix'] = array('#type' => 'textfield', '#title' => t('Prefix text placed to the left of the textfield'), '#default_value' => $config['extra']['field_prefix'], '#description' => t('Examples: $, #, -.'), '#size' => 20, '#maxlength' => 127, '#weight' => 2.1, '#parents' => array('extra', 'field_prefix'));
         $form['display']['field_suffix'] = array('#type' => 'textfield', '#title' => t('Postfix text placed to the right of the textfield'), '#default_value' => $config['extra']['field_suffix'], '#description' => t('Examples: lb, kg, %.'), '#size' => 20, '#maxlength' => 127, '#weight' => 2.2, '#parents' => array('extra', 'field_suffix'));
     }
     if ($this->supports_placeholder) {
         $form['display']['placeholder'] = array('#type' => 'textfield', '#title' => t('Placeholder'), '#default_value' => $config['extra']['placeholder'], '#description' => t('The placeholder will be shown in the field until the user starts entering a value.'), '#weight' => 1, '#parents' => array('extra', 'placeholder'));
     }
     if ($this->supports_width) {
         $form['display']['width'] = array('#type' => 'textfield', '#title' => t('Width'), '#default_value' => $config['extra']['width'], '#description' => t('Width of the textfield.') . ' ' . t('Leaving blank will use the default size.'), '#size' => 5, '#maxlength' => 10, '#weight' => 0, '#parents' => array('extra', 'width'));
     }
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => t('Save component'), '#validate' => ['::validateComponentEditForm']];
     return $form;
 }
開發者ID:Progressable,項目名稱:openway8,代碼行數:37,代碼來源:ComponentBase.php

示例10: get_node_title

 /**
  * Helper function to return a sanitized node title.
  */
 private static function get_node_title(Node $node)
 {
     if (isset($node)) {
         $nid = $node->id();
         if ($node_title = $node->getTitle()) {
             return $node_title;
         } elseif ($nid) {
             return $nid;
         }
     }
     return '—';
 }
開發者ID:Nesta,項目名稱:ddv8,代碼行數:15,代碼來源:DnaBlock.php

示例11: getCid

 public static function getCid(Node $benzinarie, Term $tip_carburant)
 {
     return 'benzinarie:' . $benzinarie->id() . ':carburant:' . $tip_carburant->id();
 }
開發者ID:hacktm15,項目名稱:lapompa,代碼行數:4,代碼來源:PretCarburant.php

示例12: isLatestVersionPage

 /**
  * Checks whether a route is the "Latest version" tab of a node.
  *
  * @param \Drupal\node\Entity\Node $node
  *   A node.
  *
  * @return bool
  *   True if the current route is the latest version tab of the given node.
  */
 public function isLatestVersionPage(Node $node)
 {
     return $this->routeMatch->getRouteName() == 'entity.node.latest_version' && ($pageNode = $this->routeMatch->getParameter('node')) && $pageNode->id() == $node->id();
 }
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:13,代碼來源:ContentPreprocess.php

示例13: checkNestedEntityEditing

 /**
  * Checks that nested IEF entity references can be edit and saved.
  *
  * @param \Drupal\node\Entity\Node $node
  *  Top level node of type ief_test_nested1 to check.
  * @param bool $ajax_submit
  *  Whether IEF form widgets should be submitted via AJax or left open.
  *
  */
 protected function checkNestedEntityEditing(Node $node, $ajax_submit = TRUE)
 {
     $this->drupalGet("node/{$node->id()}/edit");
     /** @var \Drupal\node\Entity\Node $level_1_node */
     $level_1_node = $node->test_ref_nested1->entity;
     /** @var \Drupal\node\Entity\Node $level_2_node */
     $level_2_node = $node->test_ref_nested1->entity->test_ref_nested2->entity;
     $level_2_node_update_title = $level_2_node->getTitle() . ' - updated';
     //edit-test-ref-nested1-entities-0-actions-ief-entity-edit
     $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-entities-0-actions-ief-entity-edit"]'));
     //edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-entities-0-actions-ief-entity-edit
     $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-entities-0-actions-ief-entity-edit"]'));
     $edit['test_ref_nested1[form][inline_entity_form][entities][0][form][test_ref_nested2][form][inline_entity_form][entities][0][form][title][0][value]'] = $level_2_node_update_title;
     if ($ajax_submit) {
         // Close IEF Forms with AJAX posts
         //edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-form-inline-entity-form-entities-0-form-actions-ief-edit-save
         $this->drupalPostAjaxForm(NULL, $edit, $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-form-inline-entity-form-entities-0-form-actions-ief-edit-save"]'));
         $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-form-inline-entity-form-entities-0-form-actions-ief-edit-save"]'));
         $this->drupalPostForm(NULL, [], t('Save'));
     } else {
         $this->drupalPostForm(NULL, $edit, t('Save'));
     }
     $this->nodeStorage->resetCache([$level_2_node->id()]);
     $level_2_node = $this->nodeStorage->load($level_2_node->id());
     $this->assertEqual($level_2_node_update_title, $level_2_node->getTitle());
 }
開發者ID:CIGIHub,項目名稱:bsia-drupal8,代碼行數:35,代碼來源:ComplexWidgetWebTest.php


注:本文中的Drupal\node\Entity\Node::id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。