/** * {@inheritDocs} * * Form API callback. Retrieves the value for the file_generic field element. * * This method is assigned as a #value_callback in formElement() method. */ public static function value($element, $input = FALSE, FormStateInterface $form_state) { $return = parent::value($element, $input, $form_state); // When an element is loaded, focal_point needs to be set. During a form // submission the value will already be there. if (isset($return['target_id']) && !isset($return['focal_point'])) { $element['#focal_point'] = new FocalPoint($return['target_id']); $return['focal_point'] = $element['#focal_point']->getFocalPoint(); } return $return; }
/** * {@inheritdoc} * * Form API callback. Retrieves the value for the file_generic field element. * * This method is assigned as a #value_callback in formElement() method. */ public static function value($element, $input, FormStateInterface $form_state) { $return = parent::value($element, $input, $form_state); // When an element is loaded, focal_point needs to be set. During a form // submission the value will already be there. if (isset($return['target_id']) && !isset($return['focal_point'])) { /** @var \Drupal\file\FileInterface $file */ $file = \Drupal::service('entity_type.manager') ->getStorage('file') ->load($return['target_id']); $crop_type = \Drupal::config('focal_point.settings')->get('crop_type'); $crop = Crop::findCrop($file->getFileUri(), $crop_type); if ($crop) { $anchor = \Drupal::service('focal_point.manager') ->absoluteToRelative($crop->x->value, $crop->y->value, $return['width'], $return['height']); $return['focal_point'] = "{$anchor['x']},{$anchor['y']}"; } } return $return; }