/**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     // Define element array.
     $element = [];
     foreach ($items as $delta => $item) {
         // Convert the link-field item to a \Drupal\Core\Url object.
         $url = $this->buildUrl($item);
         // Parse the URL so we can check if the path contains a Github Gist. We do
         // this to check if we should actually render the element or provide a
         // notice in the log.
         $url = UrlHelper::parse($url->getUri());
         if (FALSE !== Unicode::strpos($url['path'], 'gist.github.com')) {
             $element[$delta] = ['#theme' => 'gist_embed', '#url' => $url];
         } else {
             $entity = $items->getEntity();
             $message = $this->t('The entity type: "@type" with the ID: "@id" is trying to use a link that isn\'t a Github Gist link for the Gist Embed Formatter.', array('@type' => ucfirst($entity->getEntityType()->id()), '@id' => $entity->id()));
             \Drupal::logger('gist_embed')->notice($message);
         }
     }
     return $element;
 }
예제 #2
0
 /**
  * Tests multibyte strpos.
  *
  * @dataProvider providerStrpos
  * @covers ::strpos
  */
 public function testStrpos($haystack, $needle, $offset, $expected)
 {
     // Run through multibyte code path.
     Unicode::setStatus(Unicode::STATUS_MULTIBYTE);
     $this->assertEquals($expected, Unicode::strpos($haystack, $needle, $offset));
     // Run through singlebyte code path.
     Unicode::setStatus(Unicode::STATUS_SINGLEBYTE);
     $this->assertEquals($expected, Unicode::strpos($haystack, $needle, $offset));
 }