class MetadataEventSubscriber in Filebrowser 8.2
Same name in this branch
- 8.2 src/EventSubscriber/MetadataEventSubscriber.php \Drupal\filebrowser\EventSubscriber\MetadataEventSubscriber
- 8.2 modules/src/EventSubscriber/MetadataEventSubscriber.php \Drupal\filebrowser_extra\EventSubscriber\MetadataEventSubscriber
Same name and namespace in other branches
- 3.x modules/src/EventSubscriber/MetadataEventSubscriber.php \Drupal\filebrowser_extra\EventSubscriber\MetadataEventSubscriber
Hierarchy
- class \Drupal\filebrowser_extra\EventSubscriber\MetadataEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of MetadataEventSubscriber
1 string reference to 'MetadataEventSubscriber'
- filebrowser_extra.services.yml in modules/
filebrowser_extra.services.yml - modules/filebrowser_extra.services.yml
1 service uses MetadataEventSubscriber
File
- modules/
src/ EventSubscriber/ MetadataEventSubscriber.php, line 11
Namespace
Drupal\filebrowser_extra\EventSubscriberView source
class MetadataEventSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* @var integer
*/
protected $nid;
public static function getSubscribedEvents() {
$events['filebrowser.metadata_event'][] = [
'createModified',
0,
];
return $events;
}
// fixme: "go up" folder table cell for modified not shown
public function createModified(MetadataEvent $event) {
/** @var FilebrowserMetadataEntity $metadata */
/** @var DisplayFile $file */
$this->nid = $event->nid;
$fid = $event
->getFid();
$file = $event->file;
$columns = $event->columns;
// Only calculate modified time if this column is selected
if (!empty($columns['modified'])) {
if (isset($file->fileData->uri)) {
$file_real_path = \Drupal::service('file_system')
->realpath($file->fileData->uri);
$m_time = filemtime($file_real_path);
$m_time = empty($m_time) ? 0 : $m_time;
$content = serialize(\Drupal::service('date.formatter')
->format($m_time, 'short'));
$theme = "";
$storage = \Drupal::entityTypeManager()
->getStorage('filebrowser_metadata_entity');
$query = \Drupal::entityQuery('filebrowser_metadata_entity')
->condition('fid', $fid)
->condition('module', 'filebrowser_extra')
->condition('name', 'modified');
$entity_id = $query
->execute();
if ($entity_id) {
// entity exists, so we just update the contents
$metadata = $storage
->load(reset($entity_id));
$metadata
->setContent($content);
$metadata
->save();
}
else {
$value = [
'fid' => $fid,
'nid' => $this->nid,
'name' => 'modified',
'title' => t('Modified'),
'module' => 'filebrowser_extra',
'theme' => $theme,
'content' => $content,
];
$entity = FilebrowserMetadataEntity::create($value);
$entity
->save();
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MetadataEventSubscriber:: |
protected | property | ||
MetadataEventSubscriber:: |
public | function | ||
MetadataEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |