예제 #1
0
 /**
  * Returns an Ajax response to generate preview of embedded items.
  *
  * Expects the the HTML element as GET parameter.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param \Drupal\filter\FilterFormatInterface $filter_format
  *   The filter format.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *   Throws an exception if 'value' parameter is not found in the request.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   The preview of the embedded item specified by the data attributes.
  */
 public function preview(Request $request, FilterFormatInterface $filter_format)
 {
     $text = $request->get('value');
     if ($text == '') {
         throw new NotFoundHttpException();
     }
     $output = check_markup($text, $filter_format->id());
     $response = new AjaxResponse();
     $response->addCommand(new EmbedInsertCommand($output));
     return $response;
 }
예제 #2
0
 /**
  * Test tokens for multilingual fields and entities.
  */
 public function testMultilingualFields()
 {
     // Create an english term and add a german translation for it.
     $term = $this->createTerm($this->vocabulary, ['name' => 'english-test-term', 'langcode' => 'en', 'term_field' => ['value' => 'english-term-field-value', 'format' => $this->testFormat->id()]]);
     $term->addTranslation('de', ['name' => 'german-test-term', 'term_field' => ['value' => 'german-term-field-value', 'format' => $this->testFormat->id()]])->save();
     $german_term = $term->getTranslation('de');
     // Create an english node, add a german translation for it and add the
     // english term to the english node's entity reference field and the
     // german term to the german's entity reference field.
     $node = Node::create(['title' => 'english-node-title', 'type' => 'article', 'test_term_reference' => ['target_id' => $term->id()], 'test_field' => ['value' => 'test-english-field', 'format' => $this->testFormat->id()]]);
     $node->addTranslation('de', ['title' => 'german-node-title', 'test_term_reference' => ['target_id' => $german_term->id()], 'test_field' => ['value' => 'test-german-field', 'format' => $this->testFormat->id()]])->save();
     // Verify the :title token of the english node and the :name token of the
     // english term it refers to. Also verify the value of the term's field.
     $this->assertTokens('node', ['node' => $node], ['title' => 'english-node-title', 'test_term_reference:entity:name' => 'english-test-term', 'test_term_reference:entity:term_field:value' => 'english-term-field-value', 'test_term_reference:entity:term_field' => 'english-term-field-value', 'test_field' => 'test-english-field', 'test_field:value' => 'test-english-field']);
     // Same test for the german node and its german term.
     $german_node = $node->getTranslation('de');
     $this->assertTokens('node', ['node' => $german_node], ['title' => 'german-node-title', 'test_term_reference:entity:name' => 'german-test-term', 'test_term_reference:entity:term_field:value' => 'german-term-field-value', 'test_term_reference:entity:term_field' => 'german-term-field-value', 'test_field' => 'test-german-field', 'test_field:value' => 'test-german-field']);
     // If the langcode is specified, it should have priority over the node's
     // active language.
     $tokens = ['test_field' => 'test-german-field', 'test_field:value' => 'test-german-field', 'test_term_reference:entity:term_field' => 'german-term-field-value', 'test_term_reference:entity:term_field:value' => 'german-term-field-value'];
     $this->assertTokens('node', ['node' => $node], $tokens, ['langcode' => 'de']);
 }
예제 #3
0
파일: FieldTest.php 프로젝트: Wylbur/gj
 /**
  * Test tokens on node with the token view mode overriding default formatters.
  */
 public function testTokenViewMode()
 {
     $value = 'A really long string that should be trimmed by the special formatter on token view we are going to have.';
     // The formatter we are going to use will eventually call Unicode::strlen.
     // This expects that the Unicode has already been explicitly checked, which
     // happens in DrupalKernel. But since that doesn't run in kernel tests, we
     // explicitly call this here.
     Unicode::check();
     // Create a node with a value in the text field and test its token.
     $entity = Node::create(['title' => 'Test node title', 'type' => 'article', 'test_field' => ['value' => $value, 'format' => $this->testFormat->id()]]);
     $entity->save();
     $this->assertTokens('node', ['node' => $entity], ['test_field' => Markup::create($value)]);
     // Now, create a token view mode which sets a different format for
     // test_field. When replacing tokens, this formatter should be picked over
     // the default formatter for the field type.
     // @see field_tokens().
     $view_mode = EntityViewMode::create(['id' => 'node.token', 'targetEntityType' => 'node']);
     $view_mode->save();
     $entity_display = entity_get_display('node', 'article', 'token');
     $entity_display->setComponent('test_field', ['type' => 'text_trimmed', 'settings' => ['trim_length' => 50]]);
     $entity_display->save();
     $this->assertTokens('node', ['node' => $entity], ['test_field' => Markup::create(substr($value, 0, 50))]);
 }
예제 #4
0
 /**
  * Displays a page with long filter tips.
  *
  * @param \Drupal\filter\FilterFormatInterface|null $filter_format
  *   (optional) A filter format, or NULL to show tips for all formats.
  *   Defaults to NULL.
  *
  * @return array
  *   A renderable array.
  *
  * @see template_preprocess_filter_tips()
  */
 function filterTips(FilterFormatInterface $filter_format = NULL)
 {
     $tips = $filter_format ? $filter_format->id() : -1;
     $build = array('#theme' => 'filter_tips', '#long' => TRUE, '#tips' => _filter_tips($tips, TRUE));
     return $build;
 }