/** * {@inheritDocs} * * Validate callback for the focal point field. */ public static function validateFocalPoint($element, FormStateInterface $form_state) { $field_name = array_pop($element['#parents']); $focal_point_value = $form_state->getValue($field_name); if (!is_null($focal_point_value) && !FocalPoint::validate($focal_point_value)) { \Drupal::formBuilder()->setError($element, $form_state, t('The !title field should be in the form "leftoffset,topoffset" where offsets are in percents. Ex: 25,75.', array('!title' => $element['#title']))); } }
/** * Tests the validate() method. * * @dataProvider providerValidateFocalPoint */ public function testFocalPointValidate($focal_point, $expected) { $this->assertSame($expected, FocalPoint::validate($focal_point)); }