public function getParentNode(MediaInterface $media) {
    if (!$media->hasField(self::MEDIA_OF_FIELD)) {
      return NULL;
    }
    $field = $media->get(self::MEDIA_OF_FIELD);
    if ($field->isEmpty()) {
      return NULL;
    }
    $parent = $field->first()
      ->get('entity')
      ->getTarget();
    if (!is_null($parent)) {
      return $parent->getValue();
    }
    return NULL;
  }
public function getParentNode(MediaInterface $media) {
    if (!$media->hasField(self::MEDIA_OF_FIELD)) {
      return NULL;
    }
    $field = $media->get(self::MEDIA_OF_FIELD);
    if ($field->isEmpty()) {
      return NULL;
    }
    $parent = $field->first()
      ->get('entity')
      ->getTarget();
    if (!is_null($parent)) {
      return $parent->getValue();
    }
    return NULL;
  }
public function getParentNode ( MediaInterface $ media ) { if ( ! $ media -> hasField ( self :: MEDIA_OF_FIELD ) ) { return NULL ; } $ field = $ media -> get ( self :: MEDIA_OF_FIELD ) ; if ( $ field -> isEmpty ( ) ) { return NULL ; } $ parent = $ field -> first ( ) -> get ( 'entity' ) -> getTarget ( ) ; if ( ! is_null ( $ parent ) ) { return $ parent -> getValue ( ) ; } return NULL ; }
Gets nodes that a media belongs to.

@param \Drupal\media\MediaInterface $media
The Media whose node you are searching for.

@return \Drupal\node\NodeInterface
Parent node.

@throws \Drupal\Core\TypedData\Exception\MissingDataException
Method $field->first() throws if data structure is unset and no item can
be created.
Gets nodes that a media belongs to .