当前位置: 首页>>代码示例>>PHP>>正文


PHP Node::load方法代码示例

本文整理汇总了PHP中Drupal\node\Entity\Node::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::load方法的具体用法?PHP Node::load怎么用?PHP Node::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\node\Entity\Node的用法示例。


在下文中一共展示了Node::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: content

 public function content()
 {
     $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
     $userId = $user->get('uid')->value;
     $data = array(array('job_title' => '', 'job_path' => '', 'company_name' => '', 'application_date' => ''));
     $appliedJobs = db_select('user_job_application', 'uja')->condition('uja.user_id', $userId, '=')->fields('uja', array('job_id', 'date'))->orderBy('uja.date', 'DESC')->execute()->fetchAll();
     if ($appliedJobs) {
         $x = 0;
         foreach ($appliedJobs as $appliedJob) {
             $jobNode = \Drupal\node\Entity\Node::load($appliedJob->job_id);
             $jobTitle = $jobNode->getTitle();
             $jobPathAlias = \Drupal::service('path.alias_manager')->getAliasByPath('/node/' . $appliedJob->job_id);
             $companyNodeEntity = $jobNode->get('field_company');
             $companyNode = \Drupal\node\Entity\Node::load($companyNodeEntity->entity->id());
             $companyName = $companyNode->getTitle();
             $data[$x]['job_title'] = $jobTitle;
             $data[$x]['job_path'] = $jobPathAlias;
             $data[$x]['company_name'] = $companyName;
             $data[$x]['application_date'] = $appliedJob->date;
             $x++;
         }
     }
     $markUp = $this->createMarkUp($data);
     return array('#type' => 'markup', '#markup' => $markUp);
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:25,代码来源:JobHistoryController.php

示例2: testCckFields

 /**
  * Test CCK migration from Drupal 6 to 8.
  */
 public function testCckFields()
 {
     $node = Node::load(1);
     $this->assertIdentical('This is a shared text field', $node->field_test->value);
     $this->assertIdentical('filtered_html', $node->field_test->format);
     $this->assertIdentical('10', $node->field_test_two->value);
     $this->assertIdentical('20', $node->field_test_two[1]->value);
     $this->assertIdentical('42.42', $node->field_test_three->value, 'Single field second value is correct.');
     $this->assertIdentical('3412', $node->field_test_integer_selectlist[0]->value);
     $this->assertIdentical('1', $node->field_test_identical1->value, 'Integer value is correct');
     $this->assertIdentical('1', $node->field_test_identical2->value, 'Integer value is correct');
     $this->assertIdentical('This is a field with exclude unset.', $node->field_test_exclude_unset->value, 'Field with exclude unset is correct.');
     // Test that link fields are migrated.
     $this->assertIdentical('https://www.drupal.org/project/drupal', $node->field_test_link->uri);
     $this->assertIdentical('Drupal project page', $node->field_test_link->title);
     $this->assertIdentical(['target' => '_blank'], $node->field_test_link->options['attributes']);
     // Test the file field meta.
     $this->assertIdentical('desc', $node->field_test_filefield->description);
     $this->assertIdentical('5', $node->field_test_filefield->target_id);
     $planet_node = Node::load(3);
     $value_1 = $planet_node->field_multivalue->value;
     $value_2 = $planet_node->field_multivalue[1]->value;
     // SQLite does not support scales for float data types so we need to convert
     // the value manually.
     if ($this->container->get('database')->driver() == 'sqlite') {
         $value_1 = sprintf('%01.2f', $value_1);
         $value_2 = sprintf('%01.2f', $value_2);
     }
     $this->assertIdentical('33.00', $value_1);
     $this->assertIdentical('44.00', $value_2);
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:34,代码来源:MigrateCckFieldValuesTest.php

示例3: testEntityReferenceRevisionsAutocompleteProcessing

 /**
  * Test for autocomplete processing.
  *
  * Tests that processing does not crash when the entity types of the
  * referenced entity and of the entity the field is attached to are different.
  */
 public function testEntityReferenceRevisionsAutocompleteProcessing()
 {
     $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer nodes', 'administer blocks', 'create article content', 'administer content types', 'administer node fields', 'administer node display', 'administer node form display', 'edit any article content'));
     $this->drupalLogin($admin_user);
     // Create a custom block content bundle.
     $this->createBlockContentType(array('type' => 'customblockcontent', 'name' => 'Custom Block Content'));
     // Create entity reference revisions field attached to article.
     static::fieldUIAddNewField('admin/structure/types/manage/article', 'entity_reference_revisions', 'Entity reference revisions', 'entity_reference_revisions', array('settings[target_type]' => 'block_content', 'cardinality' => '-1'), array('settings[handler_settings][target_bundles][customblockcontent]' => TRUE));
     // Create custom block.
     $block_label = $this->randomMachineName();
     $block_content = $this->randomString();
     $edit = array('info[0][value]' => $block_label, 'body[0][value]' => $block_content, 'revision' => TRUE);
     $this->drupalPostForm('block/add', $edit, t('Save'));
     $block = $this->drupalGetBlockByInfo($block_label);
     // Create an article.
     $title = $this->randomMachineName();
     $edit = array('title[0][value]' => $title, 'body[0][value]' => 'Revision 1', 'field_entity_reference_revisions[0][target_id]' => $block_label . ' (' . $block->id() . ')', 'revision' => TRUE);
     $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
     $this->assertText($title);
     $this->assertText(Html::escape($block_content));
     // Check if the block content is not deleted since there is no composite
     // relationship.
     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $node = Node::load($node->id());
     $node->delete();
     $this->assertNotNull(BlockContent::load($block->id()));
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:33,代码来源:EntityReferenceRevisionsAutocompleteTest.php

示例4: setUp

 protected function setUp()
 {
     parent::setUp();
     // Create and log in user.
     $web_user = $this->drupalCreateUser(array('view page revisions', 'revert page revisions', 'delete page revisions', 'edit any page content', 'delete any page content'));
     $this->drupalLogin($web_user);
     // Create initial node.
     $node = $this->drupalCreateNode();
     $settings = get_object_vars($node);
     $settings['revision'] = 1;
     $settings['isDefaultRevision'] = TRUE;
     $nodes = array();
     $logs = array();
     // Get original node.
     $nodes[] = clone $node;
     // Create three revisions.
     $revision_count = 3;
     for ($i = 0; $i < $revision_count; $i++) {
         $logs[] = $node->revision_log = $this->randomMachineName(32);
         // Create revision with a random title and body and update variables.
         $node->title = $this->randomMachineName();
         $node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
         $node->setNewRevision();
         $node->save();
         $node = Node::load($node->id());
         // Make sure we get revision information.
         $nodes[] = clone $node;
     }
     $this->nodes = $nodes;
     $this->revisionLogs = $logs;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:31,代码来源:NodeRevisionsTest.php

示例5: nodeMarkup

  /**
   * Lists all instances of fields on any views.
   *
   * @return array
   *   The Views fields report page.
   */
  public function nodeMarkup($node, $key = 'default') {
    $node = Node::load($node);

    $builded_entity = entity_view($node, $key);
    $markup = drupal_render($builded_entity);

    $links = array();
    $links['default'] = array(
      'title' => 'Default',
      'url' => Url::fromRoute('ds_devel.markup', array('node' => $node->id())),
    );
    $view_modes = \Drupal::entityManager()->getViewModes('node');
    foreach ($view_modes as $id => $info) {
      if (!empty($info['status'])) {
        $links[] = array(
          'title' => $info['label'],
          'url' => Url::fromRoute('ds_devel.markup_view_mode', array('node' => $node->id(), 'key' => $id)),
        );
      }
    }

    $build['links'] = array(
      '#theme' => 'links',
      '#links' => $links,
      '#prefix' => '<div>',
      '#suffix' => '</div><hr />',
    );
    $build['markup'] = [
      '#markup' => '<code><pre>' . Html::escape($markup) . '</pre></code>',
      '#allowed_tags' => ['code', 'pre'],
    ];

    return $build;
  }
开发者ID:jkyto,项目名称:agolf,代码行数:40,代码来源:DsDevelController.php

示例6: nodeDelete

 /**
  * {@inheritdoc}
  */
 public function nodeDelete($node)
 {
     $node = $node instanceof NodeInterface ? $node : Node::load($node->nid);
     if ($node instanceof NodeInterface) {
         $node->delete();
     }
 }
开发者ID:lmakarov,项目名称:DrupalDriver,代码行数:10,代码来源:Drupal8.php

示例7: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     //TODO v2 Send Email via Cron not on Submit
     $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
     $username = $user->get('name')->value;
     $userId = $user->get('uid')->value;
     $mailManager = \Drupal::service('plugin.manager.mail');
     $jobNode = \Drupal::routeMatch()->getParameter('node');
     $jobNodeTitle = $jobNode->getTitle();
     $companyNodeEntity = $jobNode->get('field_company');
     $companyNode = \Drupal\node\Entity\Node::load($companyNodeEntity->entity->id());
     $companyEmail = $companyNode->field_email->value;
     $resumeFileId = $form_state->getValue('resume');
     $resumeFile = db_select('file_managed', 'f')->condition('f.fid', $resumeFileId, '=')->fields('f', array('uri'))->execute()->fetchField();
     $atttachment = array('filepath' => $resumeFile);
     $module = 'job_mailer';
     $key = 'apply_job';
     $params['job_title'] = $jobNodeTitle;
     $params['message'] = "<html>\n           <p>Please see attached resume for user: {$username}\n           </html>";
     $params['attachment'] = $atttachment;
     $langcode = \Drupal::currentUser()->getPreferredLangcode();
     $send = true;
     $reply = \Drupal::config('system.site')->get('mail');
     $result = $mailManager->mail($module, $key, $companyEmail, $langcode, $params, $reply, $send);
     db_insert('user_job_application')->fields(array('job_id' => $jobNode->id(), 'user_id' => $userId, 'date' => date('Y-m-d H:i:s')))->execute();
     drupal_set_message('Your application has been sent.');
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:30,代码来源:ApplyForm.php

示例8: createICal

 public function createICal($nid)
 {
     $node = \Drupal\node\Entity\Node::load($nid);
     $eventdate = $node->get('field_event_date')->getValue();
     $title = $node->get('title')->getValue();
     $title = $title[0]['value'];
     $startdate = $eventdate[0]['value'];
     $enddate = $eventdate[1]['value'];
     if (empty($enddate)) {
         $enddate = $startdate;
     }
     $startdate = self::convertDateToICal($startdate);
     $enddate = self::convertDateToICal($enddate);
     $filecontents = self::buildICSFile($startdate, $enddate, $title, $nid);
     // open raw memory as file so no temp files needed, you might run out of memory though
     $file = fopen('php://memory', 'w');
     fwrite($file, $filecontents);
     // reset the file pointer to the start of the file
     rewind($file);
     // tell the browser it's going to be a calendar file
     header('Content-Type: text/calendar; charset=utf-8');
     // tell the browser we want to save it instead of displaying it
     header('Content-Disposition: attachment; filename="calendar.ics";');
     header('Cache-Control: store, no-cache, must-revalidate, post-check=0, pre-check=0');
     // make php send the generated file to the browser
     fpassthru($file);
     exit;
     /*
     	return array(
     		'#type' => 'markup',
     		'#markup' => $this->t('Hello, ical World!<pre>' . $filecontents . "</pre>"),
     	);
     */
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:34,代码来源:ICalController.php

示例9: testMenuTokens

 function testMenuTokens()
 {
     // Add a menu.
     $menu = entity_create('menu', array('id' => 'main-menu', 'label' => 'Main menu', 'description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.'));
     $menu->save();
     // Add a root link.
     /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $root_link */
     $root_link = entity_create('menu_link_content', array('link' => ['uri' => 'internal:/admin'], 'title' => 'Administration', 'menu_name' => 'main-menu'));
     $root_link->save();
     // Add another link with the root link as the parent.
     /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $parent_link */
     $parent_link = entity_create('menu_link_content', array('link' => ['uri' => 'internal:/admin/config'], 'title' => 'Configuration', 'menu_name' => 'main-menu', 'parent' => $root_link->getPluginId()));
     $parent_link->save();
     // Test menu link tokens.
     $tokens = array('id' => $parent_link->getPluginId(), 'title' => 'Configuration', 'menu' => 'Main menu', 'menu:name' => 'Main menu', 'menu:machine-name' => $menu->id(), 'menu:description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.', 'menu:menu-link-count' => '2', 'menu:edit-url' => \Drupal::url('entity.menu.edit_form', ['menu' => 'main-menu'], array('absolute' => TRUE)), 'url' => \Drupal::url('system.admin_config', [], array('absolute' => TRUE)), 'url:absolute' => \Drupal::url('system.admin_config', [], array('absolute' => TRUE)), 'url:relative' => \Drupal::url('system.admin_config', [], array('absolute' => FALSE)), 'url:path' => 'admin/config', 'url:alias' => 'admin/config', 'edit-url' => \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $parent_link->id()], array('absolute' => TRUE)), 'parent' => 'Administration', 'parent:id' => $root_link->getPluginId(), 'parent:title' => 'Administration', 'parent:menu' => 'Main menu', 'parent:parent' => NULL, 'parents' => 'Administration', 'parents:count' => 1, 'parents:keys' => $root_link->getPluginId(), 'root' => 'Administration', 'root:id' => $root_link->getPluginId(), 'root:parent' => NULL, 'root:root' => NULL);
     $this->assertTokens('menu-link', array('menu-link' => $parent_link), $tokens);
     // Add a node.
     $node = $this->drupalCreateNode();
     // Allow main menu for this node type.
     //$this->config('menu.entity.node.' . $node->getType())->set('available_menus', array('main-menu'))->save();
     // Add a node menu link.
     /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $node_link */
     $node_link = entity_create('menu_link_content', array('link' => ['uri' => 'entity:node/' . $node->id()], 'title' => 'Node link', 'parent' => $parent_link->getPluginId(), 'menu_name' => 'main-menu'));
     $node_link->save();
     // Test [node:menu] tokens.
     $tokens = array('menu-link' => 'Node link', 'menu-link:id' => $node_link->getPluginId(), 'menu-link:title' => 'Node link', 'menu-link:menu' => 'Main menu', 'menu-link:url' => $node->url('canonical', ['absolute' => TRUE]), 'menu-link:url:path' => 'node/' . $node->id(), 'menu-link:edit-url' => $node_link->url('edit-form', ['absolute' => TRUE]), 'menu-link:parent' => 'Configuration', 'menu-link:parent:id' => $parent_link->getPluginId(), 'menu-link:parents' => 'Administration, Configuration', 'menu-link:parents:count' => 2, 'menu-link:parents:keys' => $root_link->getPluginId() . ', ' . $parent_link->getPluginId(), 'menu-link:root' => 'Administration', 'menu-link:root:id' => $root_link->getPluginId());
     $this->assertTokens('node', array('node' => $node), $tokens);
     // Reload the node which will not have $node->menu defined and re-test.
     $loaded_node = Node::load($node->id());
     $this->assertTokens('node', array('node' => $loaded_node), $tokens);
     // Regression test for http://drupal.org/node/1317926 to ensure the
     // original node object is not changed when calling menu_node_prepare().
     $this->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression');
 }
开发者ID:dev981,项目名称:gaptest,代码行数:34,代码来源:TokenMenuTest.php

示例10: testPrivateFile

 /**
  * Tests file access for file uploaded to a private node.
  */
 function testPrivateFile()
 {
     $type_name = 'article';
     $field_name = strtolower($this->randomMachineName());
     $this->createFileField($field_name, 'node', $type_name, array('uri_scheme' => 'private'));
     // Create a field with no view access. See
     // field_test_entity_field_access().
     $no_access_field_name = 'field_no_view_access';
     $this->createFileField($no_access_field_name, 'node', $type_name, array('uri_scheme' => 'private'));
     $test_file = $this->getTestFile('text');
     $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE));
     $node = node_load($nid, TRUE);
     $node_file = file_load($node->{$field_name}->target_id);
     // Ensure the file can be downloaded.
     $this->drupalGet(file_create_url($node_file->getFileUri()));
     $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.');
     $this->drupalLogOut();
     $this->drupalGet(file_create_url($node_file->getFileUri()));
     $this->assertResponse(403, 'Confirmed that access is denied for the file without the needed permission.');
     // Test with the field that should deny access through field access.
     $this->drupalLogin($this->admin_user);
     $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE));
     \Drupal::entityManager()->getStorage('node')->resetCache(array($nid));
     $node = Node::load($nid);
     $node_file = File::load($node->{$no_access_field_name}->target_id);
     // Ensure the file cannot be downloaded.
     $user = $this->drupalCreateUser(array('access content'));
     $this->drupalLogin($user);
     $this->drupalGet(file_create_url($node_file->getFileUri()));
     $this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission.');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:34,代码来源:FilePrivateTest.php

示例11: testNode

 /**
  * Test node migration from Drupal 6 to 8.
  */
 public function testNode()
 {
     $node = Node::load(1);
     $this->assertIdentical('1', $node->id(), 'Node 1 loaded.');
     $this->assertIdentical('und', $node->langcode->value);
     $this->assertIdentical('test', $node->body->value);
     $this->assertIdentical('test', $node->body->summary);
     $this->assertIdentical('filtered_html', $node->body->format);
     $this->assertIdentical('story', $node->getType(), 'Node has the correct bundle.');
     $this->assertIdentical('Test title', $node->getTitle(), 'Node has the correct title.');
     $this->assertIdentical('1388271197', $node->getCreatedTime(), 'Node has the correct created time.');
     $this->assertIdentical(FALSE, $node->isSticky());
     $this->assertIdentical('1', $node->getOwnerId());
     $this->assertIdentical('1420861423', $node->getRevisionCreationTime());
     /** @var \Drupal\node\NodeInterface $node_revision */
     $node_revision = \Drupal::entityManager()->getStorage('node')->loadRevision(1);
     $this->assertIdentical('Test title', $node_revision->getTitle());
     $this->assertIdentical('1', $node_revision->getRevisionAuthor()->id(), 'Node revision has the correct user');
     // This is empty on the first revision.
     $this->assertIdentical(NULL, $node_revision->revision_log->value);
     // Test that we can re-import using the EntityContentBase destination.
     $connection = Database::getConnection('default', 'migrate');
     $connection->update('node_revisions')->fields(array('title' => 'New node title', 'format' => 2))->condition('vid', 1)->execute();
     $connection->delete('content_field_test_two')->condition('delta', 1)->execute();
     $migration = Migration::load('d6_node__story');
     $this->executeMigration($migration);
     $node = Node::load(1);
     $this->assertIdentical('New node title', $node->getTitle());
     // Test a multi-column fields are correctly upgraded.
     $this->assertIdentical('test', $node->body->value);
     $this->assertIdentical('full_html', $node->body->format);
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:35,代码来源:MigrateNodeTest.php

示例12: testNodeRevisionDoubleEscapeFix

 /**
  * Checks HTML double escaping of revision logs.
  */
 public function testNodeRevisionDoubleEscapeFix()
 {
     $this->drupalLogin($this->editor);
     $nodes = [];
     // Create the node.
     $node = $this->drupalCreateNode();
     $username = ['#theme' => 'username', '#account' => $this->editor];
     $editor = \Drupal::service('renderer')->renderPlain($username);
     // Get original node.
     $nodes[] = clone $node;
     // Create revision with a random title and body and update variables.
     $node->title = $this->randomMachineName();
     $node->body = ['value' => $this->randomMachineName(32), 'format' => filter_default_format()];
     $node->setNewRevision();
     $revision_log = 'Revision <em>message</em> with markup.';
     $node->revision_log->value = $revision_log;
     $node->save();
     // Make sure we get revision information.
     $node = Node::load($node->id());
     $nodes[] = clone $node;
     $this->drupalGet('node/' . $node->id() . '/revisions');
     // Assert the old revision message.
     $date = format_date($nodes[0]->revision_timestamp->value, 'short');
     $url = new Url('entity.node.revision', ['node' => $nodes[0]->id(), 'node_revision' => $nodes[0]->getRevisionId()]);
     $this->assertRaw(\Drupal::l($date, $url) . ' by ' . $editor);
     // Assert the current revision message.
     $date = format_date($nodes[1]->revision_timestamp->value, 'short');
     $this->assertRaw($nodes[1]->link($date) . ' by ' . $editor . '<p class="revision-log">' . $revision_log . '</p>');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:32,代码来源:NodeRevisionsUiTest.php

示例13: contentOverview

 /**
  * Create an overview of webform content.
  */
 public function contentOverview()
 {
     // @todo This needs to be removed and the view webform_webforms used instead.
     $query = db_select('webform', 'w');
     $query->join('node', 'n', 'w.nid = n.nid');
     $query->fields('n');
     $nodes = $query->execute()->fetchAllAssoc('nid');
     module_load_include('inc', 'webform', 'includes/webform.admin');
     $header = array(t('Title'), array('data' => t('View'), 'colspan' => '4'), array('data' => t('Operations'), 'colspan' => '3'));
     $rows = array();
     if (!empty($nodes)) {
         foreach ($nodes as $node) {
             $node = Node::load($node->nid);
             $rows[] = array(\Drupal::l($node->getTitle(), Url::fromRoute('entity.node.canonical', ['node' => $node->id()])), t('Submissions'), t('Analysis'), t('Table'), t('Download'), $node->access('update') ? \Drupal::l(t('Edit'), Url::fromRoute('entity.node.edit_form', ['node' => $node->id()])) : '', t('Components'), t('Clear'));
         }
     }
     if (empty($nodes)) {
         $webform_types = webform_node_types();
         if (empty($webform_types)) {
             $message = t('Webform is currently not enabled on any content types.') . ' ' . t('Visit the <a href="!url">Webform settings</a> page and enable Webform on at least one content type.', array('!url' => Url::fromRoute('webform.settings')->toString()));
         } else {
             $webform_type_list = webform_admin_type_list();
             $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list));
         }
         $rows[] = array(array('data' => $message, 'colspan' => 7));
     }
     $table = array('#type' => 'table', '#header' => $header, '#rows' => $rows);
     return $table;
 }
开发者ID:Progressable,项目名称:openway8,代码行数:32,代码来源:WebformController.php

示例14: testSummaryLength

 /**
  * Tests the node summary length functionality.
  */
 public function testSummaryLength()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     // Create a node to view.
     $settings = array('body' => array(array('value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero. Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci. Curabitur feugiat egestas nisl sed accumsan.')), 'promote' => 1);
     $node = $this->drupalCreateNode($settings);
     $this->assertTrue(Node::load($node->id()), 'Node created.');
     // Render the node as a teaser.
     $content = $this->drupalBuildEntityView($node, 'teaser');
     $this->assertTrue(strlen($content['body'][0]['#markup']) < 600, 'Teaser is less than 600 characters long.');
     $this->setRawContent($renderer->renderRoot($content));
     // The string 'What is a Drupalism?' is between the 200th and 600th
     // characters of the node body, so it should be included if the summary is
     // 600 characters long.
     $expected = 'What is a Drupalism?';
     $this->assertRaw($expected);
     // Change the teaser length for "Basic page" content type.
     $display = entity_get_display('node', $node->getType(), 'teaser');
     $display_options = $display->getComponent('body');
     $display_options['settings']['trim_length'] = 200;
     $display->setComponent('body', $display_options)->save();
     // Render the node as a teaser again and check that the summary is now only
     // 200 characters in length and so does not include 'What is a Drupalism?'.
     $content = $this->drupalBuildEntityView($node, 'teaser');
     $this->assertTrue(strlen($content['body'][0]['#markup']) < 200, 'Teaser is less than 200 characters long.');
     $this->setRawContent($renderer->renderRoot($content));
     $this->assertText($node->label());
     $this->assertNoRaw($expected);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:33,代码来源:SummaryLengthTest.php

示例15: testAutoCreate

 /**
  * Tests that the autocomplete input element appears and the creation of a new
  * entity.
  */
 public function testAutoCreate()
 {
     $this->drupalGet('node/add/' . $this->referencingType);
     $this->assertFieldByXPath('//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]', NULL, 'The autocomplete input element appears.');
     $new_title = $this->randomMachineName();
     // Assert referenced node does not exist.
     $base_query = \Drupal::entityQuery('node');
     $base_query->condition('type', $this->referencedType)->condition('title', $new_title);
     $query = clone $base_query;
     $result = $query->execute();
     $this->assertFalse($result, 'Referenced node does not exist yet.');
     $edit = array('title[0][value]' => $this->randomMachineName(), 'test_field[0][target_id]' => $new_title);
     $this->drupalPostForm("node/add/{$this->referencingType}", $edit, 'Save');
     // Assert referenced node was created.
     $query = clone $base_query;
     $result = $query->execute();
     $this->assertTrue($result, 'Referenced node was created.');
     $referenced_nid = key($result);
     $referenced_node = Node::load($referenced_nid);
     // Assert the referenced node is associated with referencing node.
     $result = \Drupal::entityQuery('node')->condition('type', $this->referencingType)->execute();
     $referencing_nid = key($result);
     $referencing_node = Node::load($referencing_nid);
     $this->assertEqual($referenced_nid, $referencing_node->test_field->target_id, 'Newly created node is referenced from the referencing node.');
     // Now try to view the node and check that the referenced node is shown.
     $this->drupalGet('node/' . $referencing_node->id());
     $this->assertText($referencing_node->label(), 'Referencing node label found.');
     $this->assertText($referenced_node->label(), 'Referenced node label found.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:33,代码来源:EntityReferenceAutoCreateTest.php


注:本文中的Drupal\node\Entity\Node::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。