UpdateMetadataAction.php in Bynder 8.3
Same filename and directory in other branches
Namespace
Drupal\bynder\Plugin\ActionFile
src/Plugin/Action/UpdateMetadataAction.phpView source
<?php
namespace Drupal\bynder\Plugin\Action;
use Drupal\bynder\Plugin\Field\FieldType\BynderMetadataItem;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Action\Plugin\Action\EntityActionBase;
use Drupal\Core\Session\AccountInterface;
/**
* Updates the Bynder metadata.
*
* @Action(
* id = "bynder_metadata",
* action_label = @Translation("Update Bynder metadata"),
* type = "media"
* )
*/
class UpdateMetadataAction extends EntityActionBase {
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$entity
->getSource()
->ensureMetadata($entity, TRUE);
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
if (!$object
->hasField(BynderMetadataItem::METADATA_FIELD_NAME) || $object
->get(BynderMetadataItem::METADATA_FIELD_NAME)
->getFieldDefinition()
->getType() !== 'bynder_metadata') {
return $return_as_object ? AccessResult::forbidden() : FALSE;
}
return $return_as_object ? AccessResult::allowed() : TRUE;
}
}
Classes
Name | Description |
---|---|
UpdateMetadataAction | Updates the Bynder metadata. |