public function Bynder::getSourceFieldValue in Bynder 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/media/Source/Bynder.php \Drupal\bynder\Plugin\media\Source\Bynder::getSourceFieldValue()
- 4.0.x src/Plugin/media/Source/Bynder.php \Drupal\bynder\Plugin\media\Source\Bynder::getSourceFieldValue()
Get the primary value stored in the source field.
@todo This helper method was added to MediaSourceBase in 8.5.0 but we replicate it here because we want to support 8.4.0 sites as well. This method can be safely removed once there is no need to support 8.4 anymore, and we ensure the core Media dependency is bumped to 8.5.0 at least.
Parameters
\Drupal\media\MediaInterface $media: A media item.
Return value
mixed The source value.
Throws
\RuntimeException If the source field for the media source is not defined.
Overrides MediaSourceBase::getSourceFieldValue
2 calls to Bynder::getSourceFieldValue()
- Bynder::ensureMetadata in src/
Plugin/ media/ Source/ Bynder.php - Ensures the given media entity has Bynder metadata information in place.
- Bynder::getMetadata in src/
Plugin/ media/ Source/ Bynder.php - Gets the value for a metadata attribute for a given media item.
File
- src/
Plugin/ media/ Source/ Bynder.php, line 416
Class
- Bynder
- Provides media source plugin for Bynder.
Namespace
Drupal\bynder\Plugin\media\SourceCode
public function getSourceFieldValue(MediaInterface $media) {
$source_field = $this->configuration['source_field'];
if (empty($source_field)) {
throw new \RuntimeException('Source field for media source is not defined.');
}
/** @var \Drupal\Core\Field\FieldItemInterface $field_item */
$field_item = $media
->get($source_field)
->first();
return $field_item->{$field_item
->mainPropertyName()};
}