public static function Heartbeat::mediaFieldTypes in Heartbeat 8
Returns all media types for an array of fields
Parameters
$fields:
Return value
array
Throws
\Drupal\Core\Entity\Exception\UndefinedLinkTemplateException
\Drupal\Core\Entity\EntityMalformedException
File
- src/
Entity/ Heartbeat.php, line 744
Class
Namespace
Drupal\heartbeat\EntityCode
public static function mediaFieldTypes($fields) {
$types = array();
foreach ($fields as $field) {
if ($field instanceof \Drupal\file\Plugin\Field\FieldType\FileFieldItemList) {
if ($field
->getFieldDefinition()
->getType() === 'image' || $field
->getFieldDefinition()
->getType() === 'video' || $field
->getFieldDefinition()
->getType() === 'audio') {
$fieldValue = $field
->getValue();
foreach ($fieldValue as $value) {
$file = \Drupal::entityTypeManager()
->getStorage('file')
->load($value['target_id']);
if ($file !== NULL && is_object($file)) {
$url = Url::fromUri($file
->getFileUri());
$posfind = strpos($url
->getUri(), 'youtube://');
if ($posfind !== 0 && $posfind === false) {
$mediaObject = self::createHeartbeatMedia($field
->getFieldDefinition()
->getType(), $url
->getUri());
}
else {
$mediaObject = self::createHeartbeatMedia('youtube', $url
->getUri());
}
$types[] = $mediaObject;
}
else {
continue;
}
}
}
}
}
return $types;
}