public function getMediaData($currentId, $dateComparator, $sortOrder, $thumbnail)
    {
        /**
         * @var $current \Drupal\media_entity\Entity\Media
         */
        $current = $this->entityTypeManager
            ->getStorage('media')
            ->load($currentId);

        if(!$current)
        {
            return null;
        }

        $prev_or_next = \Drupal::entityQuery('media')
            ->condition('bundle', $current->bundle())
            ->condition('status', 1)
            ->condition('created', $current->getCreatedTime(), $dateComparator)
            ->sort('created', $sortOrder)
            ->range(0, 1)
            ->execute();

        if(!$prev_or_next)
        {
            return null;
        }

        $gallery = $this->entityTypeManager
            ->getStorage('media')
            ->load(array_values($prev_or_next)[0]);

        $all = $gallery->get('field_media_images');
        if(isset($all[0]))
        {
            $file   = $all[0]->entity->field_image->entity->getFileUri();

            return [
                'id'        => $gallery->id(),
                'title'     => $gallery->label(),
                'path'      => $gallery->toUrl()->toString(),
                'images'    => $all,
                'thumb'     => ImageStyle::load($thumbnail)->buildUrl($file)
            ];
        }


        return null;
    }
public function getMediaData($currentId, $dateComparator, $sortOrder, $thumbnail)
    {
        /**
         * @var $current \Drupal\media_entity\Entity\Media
         */
        $current = $this->entityTypeManager
            ->getStorage('media')
            ->load($currentId);

        if(!$current)
        {
            return null;
        }

        $prev_or_next = \Drupal::entityQuery('media')
            ->condition('bundle', $current->bundle())
            ->condition('status', 1)
            ->condition('created', $current->getCreatedTime(), $dateComparator)
            ->sort('created', $sortOrder)
            ->range(0, 1)
            ->execute();

        if(!$prev_or_next)
        {
            return null;
        }

        $gallery = $this->entityTypeManager
            ->getStorage('media')
            ->load(array_values($prev_or_next)[0]);

        $all = $gallery->get('field_media_images');
        if(isset($all[0]))
        {
            $file   = $all[0]->entity->field_image->entity->getFileUri();

            return [
                'id'        => $gallery->id(),
                'title'     => $gallery->label(),
                'path'      => $gallery->toUrl()->toString(),
                'images'    => $all,
                'thumb'     => ImageStyle::load($thumbnail)->buildUrl($file)
            ];
        }


        return null;
    }
public function getMediaData ( $ currentId , $ dateComparator , $ sortOrder , $ thumbnail ) { /**
         * @var $current \Drupal\media_entity\Entity\Media
         */ $ current = $ this -> entityTypeManager -> getStorage ( 'media' ) -> load ( $ currentId ) ; if ( ! $ current ) { return null ; } $ prev_or_next = \ Drupal :: entityQuery ( 'media' ) -> condition ( 'bundle' , $ current -> bundle ( ) ) -> condition ( 'status' , 1 ) -> condition ( 'created' , $ current -> getCreatedTime ( ) , $ dateComparator ) -> sort ( 'created' , $ sortOrder ) -> range ( 0 , 1 ) -> execute ( ) ; if ( ! $ prev_or_next ) { return null ; } $ gallery = $ this -> entityTypeManager -> getStorage ( 'media' ) -> load ( array_values ( $ prev_or_next ) [ 0 ] ) ; $ all = $ gallery -> get ( 'field_media_images' ) ; if ( isset ( $ all [ 0 ] ) ) { $ file = $ all [ 0 ] -> entity -> field_image -> entity -> getFileUri ( ) ; return [ 'id' => $ gallery -> id ( ) , 'title' => $ gallery -> label ( ) , 'path' => $ gallery -> toUrl ( ) -> toString ( ) , 'images' => $ all , 'thumb' => ImageStyle :: load ( $ thumbnail ) -> buildUrl ( $ file ) ] ; } return null ; }
Load one gallery
@param $currentId
@param $dateComparator
@param $sortOrder
@param $thumbnail
@return array|null
Load one gallery