当前位置: 首页>>代码示例>>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;未经允许,请勿转载。