original_string: protected function generateEntityReferenceLinks(EntityInterface $entity) {
      // Use the node to add link headers for each entity reference.
      $entity_type = $entity->getEntityType()->id();
      $bundle = $entity->bundle();
  
      // Get all fields for the entity.
      $fields = $this->entityFieldManager->getFieldDefinitions($entity_type, $bundle);
  
      // Strip out everything but entity references that are not base fields.
      $entity_reference_fields = array_filter($fields, function ($field) {
        return $field->getFieldStorageDefinition()->isBaseField() == FALSE && $field->getType() == "entity_reference";
      });
  
      // Collect links for referenced entities.
      $links = [];
      foreach ($entity_reference_fields as $field_name => $field_definition) {
        foreach ($entity->get($field_name)->referencedEntities() as $referencedEntity) {
          // Headers are subject to an access check.
          if ($referencedEntity->access('view')) {
  
            // Taxonomy terms are written out as
            // <url>; rel="tag"; title="Tag Name"
            // where url is defined in field_same_as.
            // If field_same_as doesn't exist or is empty,
            // it becomes the taxonomy term's local uri.
            if ($referencedEntity->getEntityTypeId() == 'taxonomy_term') {
              $rel = "tag";
              $entity_url = $referencedEntity->url('canonical', ['absolute' => TRUE]);
              if ($referencedEntity->hasField('field_external_uri')) {
                $external_uri = $referencedEntity->get('field_external_uri')->getValue();
                if (!empty($external_uri) && isset($external_uri[0]['uri'])) {
                  $entity_url = $external_uri[0]['uri'];
                }
              }
              $title = $referencedEntity->label();
            }
            else {
              // If it's not a taxonomy term, referenced entity link
              // headers take the form
              // <url>; rel="related"; title="Field Label"
              // and the url is the local uri.
              $rel = "related";
              $entity_url = $referencedEntity->url('canonical', ['absolute' => TRUE]);
              $title = $field_definition->label();
            }
            $links[] = "<$entity_url>; rel=\"$rel\"; title=\"$title\"";
          }
        }
      }
  
      return $links;
    }
code: protected function generateEntityReferenceLinks(EntityInterface $entity) {
      // Use the node to add link headers for each entity reference.
      $entity_type = $entity->getEntityType()->id();
      $bundle = $entity->bundle();
  
      // Get all fields for the entity.
      $fields = $this->entityFieldManager->getFieldDefinitions($entity_type, $bundle);
  
      // Strip out everything but entity references that are not base fields.
      $entity_reference_fields = array_filter($fields, function ($field) {
        return $field->getFieldStorageDefinition()->isBaseField() == FALSE && $field->getType() == "entity_reference";
      });
  
      // Collect links for referenced entities.
      $links = [];
      foreach ($entity_reference_fields as $field_name => $field_definition) {
        foreach ($entity->get($field_name)->referencedEntities() as $referencedEntity) {
          // Headers are subject to an access check.
          if ($referencedEntity->access('view')) {
  
            // Taxonomy terms are written out as
            // <url>; rel="tag"; title="Tag Name"
            // where url is defined in field_same_as.
            // If field_same_as doesn't exist or is empty,
            // it becomes the taxonomy term's local uri.
            if ($referencedEntity->getEntityTypeId() == 'taxonomy_term') {
              $rel = "tag";
              $entity_url = $referencedEntity->url('canonical', ['absolute' => TRUE]);
              if ($referencedEntity->hasField('field_external_uri')) {
                $external_uri = $referencedEntity->get('field_external_uri')->getValue();
                if (!empty($external_uri) && isset($external_uri[0]['uri'])) {
                  $entity_url = $external_uri[0]['uri'];
                }
              }
              $title = $referencedEntity->label();
            }
            else {
              // If it's not a taxonomy term, referenced entity link
              // headers take the form
              // <url>; rel="related"; title="Field Label"
              // and the url is the local uri.
              $rel = "related";
              $entity_url = $referencedEntity->url('canonical', ['absolute' => TRUE]);
              $title = $field_definition->label();
            }
            $links[] = "<$entity_url>; rel=\"$rel\"; title=\"$title\"";
          }
        }
      }
  
      return $links;
    }
code_tokens: protected function generateEntityReferenceLinks ( EntityInterface $ entity ) { // Use the node to add link headers for each entity reference. $ entity_type = $ entity -> getEntityType ( ) -> id ( ) ; $ bundle = $ entity -> bundle ( ) ; // Get all fields for the entity. $ fields = $ this -> entityFieldManager -> getFieldDefinitions ( $ entity_type , $ bundle ) ; // Strip out everything but entity references that are not base fields. $ entity_reference_fields = array_filter ( $ fields , function ( $ field ) { return $ field -> getFieldStorageDefinition ( ) -> isBaseField ( ) == FALSE && $ field -> getType ( ) == "entity_reference" ; } ) ; // Collect links for referenced entities. $ links = [ ] ; foreach ( $ entity_reference_fields as $ field_name => $ field_definition ) { foreach ( $ entity -> get ( $ field_name ) -> referencedEntities ( ) as $ referencedEntity ) { // Headers are subject to an access check. if ( $ referencedEntity -> access ( 'view' ) ) { // Taxonomy terms are written out as // <url>; rel="tag"; title="Tag Name" // where url is defined in field_same_as. // If field_same_as doesn't exist or is empty, // it becomes the taxonomy term's local uri. if ( $ referencedEntity -> getEntityTypeId ( ) == 'taxonomy_term' ) { $ rel = "tag" ; $ entity_url = $ referencedEntity -> url ( 'canonical' , [ 'absolute' => TRUE ] ) ; if ( $ referencedEntity -> hasField ( 'field_external_uri' ) ) { $ external_uri = $ referencedEntity -> get ( 'field_external_uri' ) -> getValue ( ) ; if ( ! empty ( $ external_uri ) && isset ( $ external_uri [ 0 ] [ 'uri' ] ) ) { $ entity_url = $ external_uri [ 0 ] [ 'uri' ] ; } } $ title = $ referencedEntity -> label ( ) ; } else { // If it's not a taxonomy term, referenced entity link // headers take the form // <url>; rel="related"; title="Field Label" // and the url is the local uri. $ rel = "related" ; $ entity_url = $ referencedEntity -> url ( 'canonical' , [ 'absolute' => TRUE ] ) ; $ title = $ field_definition -> label ( ) ; } $ links [ ] = "<$entity_url>; rel=\"$rel\"; title=\"$title\"" ; } } } return $ links ; }
docstring: Generates link headers for each referenced entity.
  
  @param \Drupal\Core\Entity\EntityInterface $entity
  Entity that has reference fields.
  
  @return string[]
  Array of link headers
docstring_tokens: Generates link headers for each referenced entity .