Photos.php in Album Photos 8.5
File
src/Plugin/media/Source/Photos.php
View source
<?php
namespace Drupal\photos\Plugin\media\Source;
use Drupal\media\MediaInterface;
use Drupal\media\MediaSourceBase;
class Photos extends MediaSourceBase {
public function getMetadataAttributes() {
return [];
}
public function getMetadata(MediaInterface $media, $attribute_name) {
$source_field = $this->configuration['source_field'];
if (!$source_field) {
return parent::getMetadata($media, $attribute_name);
}
switch ($attribute_name) {
case 'default_name':
$nid = $media
->get($source_field)->target_id;
$node = $this->entityTypeManager
->getStorage('node')
->load($nid);
if ($node) {
return $node
->getTitle();
}
return parent::getMetadata($media, $attribute_name);
case 'thumbnail_uri':
default:
return parent::getMetadata($media, $attribute_name);
}
}
}
Classes
Name |
Description |
Photos |
Photos album media source. |