reverted: --- b/config/install/focal_point.settings.yml +++ a/config/install/focal_point.settings.yml @@ -1 +1,2 @@ crop_type: 'focal_point' +default_value: '50,50' diff -u b/config/schema/focal_point.schema.yml b/config/schema/focal_point.schema.yml --- b/config/schema/focal_point.schema.yml +++ b/config/schema/focal_point.schema.yml @@ -5,6 +5,9 @@ crop_type: type: string label: 'Crop type to be used with Focal point' + default_value: + type: string + label: 'The default value to use for focal point when none is specified' image.effect.focal_point_scale_and_crop: type: image_size @@ -19,0 +23,17 @@ + +field.widget.settings.image_focal_point: + type: mapping + label: 'Focal Point widget settings' + mapping: + progress_indicator: + type: string + label: 'Progress indicator' + preview_image_style: + type: string + label: 'Preview image style' + preview_link: + type: boolean + label: 'Preview link' + offsets: + type: string + label: 'Focal point offsets' diff -u b/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php b/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php --- b/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php +++ b/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php @@ -28,10 +28,12 @@ * {@inheritdoc} */ public static function defaultSettings() { - return array( - 'preview_link' => TRUE, - 'offsets' => '50,50', - ) + parent::defaultSettings(); + return [ + 'progress_indicator' => 'throbber', + 'preview_image_style' => 'thumbnail', + 'preview_link' => TRUE, + 'offsets' => '50,50', + ] + parent::defaultSettings(); } /** @@ -41,12 +43,12 @@ $form = parent::settingsForm($form, $form_state); // We need a preview image for this widget. - $form['preview_image_style']['#required'] = DRUPAL_REQUIRED; + $form['preview_image_style']['#required'] = TRUE; unset($form['preview_image_style']['#empty_option']); $form['preview_link'] = [ '#type' => 'checkbox', - '#title' => $this->t('Show preview link'), + '#title' => $this->t('Preview link'), '#default_value' => $this->getSetting('preview_link'), '#weight' => 30, ]; @@ -59,7 +61,7 @@ '#size' => 7, '#maxlength' => 7, '#element_validate' => [[$this, 'validateFocalPointWidget']], - '#required' => DRUPAL_REQUIRED, + '#required' => TRUE, '#weight' => 35, ]; @@ -86,7 +88,7 @@ */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { $element = parent::formElement($items, $delta, $element, $form, $form_state); - $element['#process'][] = [get_called_class(), 'process']; + $element['#process'][] = [static::class, 'process']; $element['#focal_point'] = [ 'preview_link' => $this->getSetting('preview_link'), 'offsets' => $this->getSetting('offsets'), @@ -102,9 +104,9 @@ * This method is assigned as a #process callback in formElement() method. * * @todo Implement https://www.drupal.org/node/2657592 - * Convert focal point selector tool into a standalone form element - * @todo Make Focal Point element accessible - * by using visually-hidden, focusable, and cleanup focal_point.js. + * Convert focal point selector tool into a standalone form element. + * @todo Implement https://www.drupal.org/node/2848511 + * Focal Point offsets not accessible by keyboard. */ public static function process($element, FormStateInterface $form_state, $form) { $element = parent::process($element, $form_state, $form); @@ -181,7 +183,7 @@ '#title' => new TranslatableMarkup('Focal point'), '#description' => new TranslatableMarkup('Specify the focus of this image in the form "leftoffset,topoffset" where offsets are in percents. Ex: 25,75'), '#default_value' => $default_focal_point_value, - '#element_validate' => [[get_called_class(),'validateFocalPoint']], + '#element_validate' => [[static::class, 'validateFocalPoint']], '#attributes' => array( 'class' => array('focal-point', $element_selector), 'data-selector' => $element_selector, @@ -229,8 +231,6 @@ /** * Validation Callback; Focal Point process field. - * - * @todo Merge validateFocalPoint() & validateFocalPointWidget(). */ public static function validateFocalPoint($element, FormStateInterface $form_state) { if (empty($element['#value']) || (FALSE === \Drupal::service('focal_point.manager')->validateFocalPoint($element['#value']))) { @@ -241,14 +241,9 @@ /** * Validation Callback; Focal Point widget setting. - * - * @todo Merge validateFocalPoint() & validateFocalPointWidget(). */ public function validateFocalPointWidget(array &$element, FormStateInterface $form_state) { - if (empty($element['#value']) || (FALSE === \Drupal::service('focal_point.manager')->validateFocalPoint($element['#value']))) { - $replacements = ['@title' => strtolower($element['#title'])]; - $form_state->setError($element, $this->t('The @title field should be in the form "leftoffset,topoffset" where offsets are in percentages. Ex: 25,75.', $replacements)); - } + static::validateFocalPoint($element, $form_state); } /**