Esempio n. 1
0
 /**
  * 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);
 }
 /**
  * Tests the node comment statistics.
  */
 function testCommentNodeCommentStatistics()
 {
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     $this->drupalGet('<front>');
     $this->assertNoLink(t('1 comment'));
     $this->assertEqual($this->node->get('comment')->comment_count, 0, 'The number of comments for the node is correct (0 comments)');
     // Test comment statistic when creating comments.
     $comment1 = Comment::create(['entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'How much wood would a woodchuck chuck', 'comment_body' => $this->randomMachineName(128), 'entity_id' => $this->node->id()]);
     $comment1->save();
     $node_storage->resetCache([$this->node->id()]);
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->comment_count, 1, 'The number of comments for the node is correct (1 comment)');
     $this->drupalGet('<front>');
     $this->assertLink(t('1 comment'));
     $comment2 = Comment::create(['entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'A big black bug bit a big black dog', 'comment_body' => $this->randomMachineName(128), 'entity_id' => $this->node->id()]);
     $comment2->save();
     $comment3 = Comment::create(['entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'How much pot, could a pot roast roast', 'comment_body' => $this->randomMachineName(128), 'entity_id' => $this->node->id()]);
     $comment3->save();
     $node_storage->resetCache([$this->node->id()]);
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->comment_count, 3, 'The number of comments for the node is correct (3 comments)');
     $this->drupalGet('<front>');
     $this->assertLink(t('3 comments'));
     // Test comment statistic when deleting comments.
     $comment1->delete();
     $comment2->delete();
     $node_storage->resetCache([$this->node->id()]);
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->comment_count, 1, 'The number of comments for the node is correct (1 comment)');
     $this->drupalGet('<front>');
     $this->assertLink(t('1 comment'));
     $comment3->delete();
     $node_storage->resetCache([$this->node->id()]);
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->comment_count, 0, 'The number of comments for the node is correct (0 comments)');
     $this->drupalGet('<front>');
     $this->assertNoLink(t('1 comment'));
     $this->assertNoLink(t('comments'));
 }
Esempio n. 3
0
 /**
  * Tests output for properties held in common between articles and pages.
  *
  * @param \EasyRdf_Graph $graph
  *   The EasyRDF graph object.
  * @param \Drupal\node\NodeInterface $node
  *   The node being displayed.
  * @param string $message_prefix
  *   The word to use in the test assertion message.
  */
 protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $message_prefix)
 {
     $uri = $node->url('canonical', array('absolute' => TRUE));
     // Title.
     $expected_value = array('type' => 'literal', 'value' => $node->get('title')->value, 'lang' => 'en');
     $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/name', $expected_value), "{$message_prefix} title was found (schema:name).");
     // Created date.
     $expected_value = array('type' => 'literal', 'value' => format_date($node->get('created')->value, 'custom', 'c', 'UTC'), 'lang' => 'en');
     $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "{$message_prefix} created date was found (schema:dateCreated) in teaser.");
     // Body.
     $expected_value = array('type' => 'literal', 'value' => $node->get('body')->value, 'lang' => 'en');
     $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/text', $expected_value), "{$message_prefix} body was found (schema:text) in teaser.");
     // Author.
     $expected_value = array('type' => 'uri', 'value' => $this->authorUri);
     $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/author', $expected_value), "{$message_prefix} author was found (schema:author) in teaser.");
     // Author type.
     $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "{$message_prefix} author type was found (schema:Person).");
     // Author name.
     $expected_value = array('type' => 'literal', 'value' => $this->adminUser->label());
     $this->assertTrue($graph->hasProperty($this->authorUri, 'http://schema.org/name', $expected_value), "{$message_prefix} author name was found (schema:name).");
 }
Esempio n. 4
0
  /**
   * Prepares a revision to be reverted.
   *
   * @param \Drupal\node\NodeInterface $revision
   *   The revision to be reverted.
   *   The type of $revision should be
   *   \Drupal\Core\Entity\ContentEntityInterface. But at the moment we need to
   *   stay compatible with
   *   \Drupal\node\Form\NodeRevisionRevertForm::prepareRevertedRevision(). See
   *   https://www.drupal.org/node/2350939
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return \Drupal\node\NodeInterface
   *   The prepared revision ready to be stored.
   */
  protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) {
    foreach ($revision->getFieldDefinitions() as $field_name => $definition) {
      if ($form_state->getValue('revert_' . $field_name)) {
        $this->latestRevision->set($field_name, $revision->get($field_name)->getValue());
      }
    }

    $this->latestRevision->setNewRevision();
    $this->latestRevision->isDefaultRevision(TRUE);

    return $this->latestRevision;
  }