Skip to content
Snippets Groups Projects

3218426: Fix issue with partially translated images and moderation. Re-rolled...

2 files
+ 177
15
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -323,24 +323,41 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
@@ -323,24 +323,41 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function preSave() {
public function onChange($property_name, $notify = TRUE) {
parent::preSave();
parent::onChange($property_name, $notify);
$width = $this->width;
$height = $this->height;
// Determine the dimensions if necessary.
// Determine the dimensions if necessary.
if ($this->entity && $this->entity instanceof EntityInterface) {
if (!$this->entity instanceof EntityInterface) {
if (empty($width) || empty($height)) {
return;
$image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
if ($image->isValid()) {
$this->width = $image->getWidth();
$this->height = $image->getHeight();
}
}
}
}
else {
$this->getLogger('image')->warning("Missing file with ID %id.", ['%id' => $this->target_id]);
if ($property_name === 'width' || $property_name === 'height') {
 
return;
 
}
 
 
$width = $this->get('width')->getValue();
 
$height = $this->get('height')->getValue();
 
 
if ($width !== NULL && $height !== NULL) {
 
return;
 
}
 
 
$image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
 
if (!$image->isValid()) {
 
return;
 
}
 
 
$this->set('width', $image->getWidth());
 
$this->set('height', $image->getHeight());
 
}
 
 
/**
 
* {@inheritdoc}
 
*/
 
public function preSave() {
 
parent::preSave();
 
if (!$this->entity instanceof EntityInterface) {
 
trigger_error(sprintf("Missing file with ID %s.", $this->target_id), E_USER_WARNING);
}
}
}
}
Loading