protected function FileEntity::updateImageFieldDimensions in File Entity (fieldable files) 8.2
Updates the image dimensions stored in any image fields for a file.
See also
http://drupal.org/node/1448124
1 call to FileEntity::updateImageFieldDimensions()
- FileEntity::postSave in src/
Entity/ FileEntity.php - Implements hook_file_insert().
File
- src/
Entity/ FileEntity.php, line 240
Class
- FileEntity
- Replace for the core file entity class.
Namespace
Drupal\file_entity\EntityCode
protected function updateImageFieldDimensions() {
// Prevent PHP notices when trying to read empty files.
// @see http://drupal.org/node/681042
if (!$this
->getSize()) {
return;
}
// Do not bother proceeding if this file does not have an image mime type.
if ($this
->getMimeTypeType() != 'image') {
return;
}
// Find all image field enabled on the site.
$image_fields = \Drupal::service('entity_field.manager')
->getFieldMapByFieldType('image');
foreach ($image_fields as $entity_type_id => $field_names) {
foreach (array_keys($field_names) as $image_field) {
$ids = \Drupal::entityQuery($entity_type_id)
->condition($image_field . '.target_id', $this
->id())
->execute();
$entities = \Drupal::entityTypeManager()
->getStorage($entity_type_id)
->loadMultiple($ids);
foreach ($entities as $entity) {
$this
->updateImageFieldDimensionsByEntity($entity, $image_field);
}
}
}
}