diff --git a/config/schema/google_vision.schema.yml b/config/schema/google_vision.schema.yml index bcb997e..884df2a 100644 --- a/config/schema/google_vision.schema.yml +++ b/config/schema/google_vision.schema.yml @@ -13,3 +13,11 @@ google_vision.settings: api_key: type: string label: 'Google Vision Api Key' + +field.field.*.*.*.third_party.google_vision: + type: mapping + label: 'Per-image field safe search settings' + mapping: + safe_search: + type: boolean + label: 'Safe Search' diff --git a/google_vision.module b/google_vision.module index dea6244..4855e94 100644 --- a/google_vision.module +++ b/google_vision.module @@ -63,7 +63,7 @@ function google_vision_form_field_config_edit_form_alter(&$form, \Drupal\Core\Fo '#type' => 'checkbox', '#title' => t('Enable Safe Search'), '#description' => t('Detects and avoids explicit contents.'), - '#default_value' => !empty($settings['google_vision']) ? $settings['google_vision'] : FALSE, + '#default_value' => !empty($settings['safe_search']) ? $settings['safe_search'] : FALSE, ]; $form['#entity_builders'][] = 'google_vision_form_field_config_form_image_builder'; @@ -94,7 +94,7 @@ function google_vision_entity_bundle_field_info_alter(&$fields, EntityTypeInterf * Form builder to save the settings for images. */ function google_vision_form_field_config_form_image_builder($entity_type, FieldConfigInterface $type, &$form, FormStateInterface $form_state) { - $type->setThirdPartySetting('google_vision', 'google_vision', $form_state->getValue('safe_search')); + $type->setThirdPartySetting('google_vision', 'safe_search', $form_state->getValue('safe_search')); } /** diff --git a/src/Plugin/Validation/Constraint/SafeSearchConstraintValidator.php b/src/Plugin/Validation/Constraint/SafeSearchConstraintValidator.php index 4ace233..c49d7de 100755 --- a/src/Plugin/Validation/Constraint/SafeSearchConstraintValidator.php +++ b/src/Plugin/Validation/Constraint/SafeSearchConstraintValidator.php @@ -53,7 +53,7 @@ class SafeSearchConstraintValidator extends ConstraintValidator implements Conta $field_def = $data->getFieldDefinition(); $settings = $field_def->getThirdPartySettings('google_vision'); // if the Safe Search detection is on. - if (!empty($settings['google_vision'])) { + if (!empty($settings['safe_search'])) { // if the image is uploaded. if (!empty($data->getValue('target_id'))) { // Retrieve the file uri. diff --git a/src/Tests/SafeSearchConstraintValidationTest.php b/src/Tests/SafeSearchConstraintValidationTest.php index 4e249c1..5a0dab4 100644 --- a/src/Tests/SafeSearchConstraintValidationTest.php +++ b/src/Tests/SafeSearchConstraintValidationTest.php @@ -29,12 +29,6 @@ class SafeSearchConstraintValidationTest extends WebTestBase { public static $modules = ['google_vision', 'node', 'image', 'field_ui', 'field']; /** - * The schema is restricted as only the Safe Search option needs to be enabled - * or disabled which does not require changing the schema. - */ - protected $strictConfigSchema = FALSE; - - /** * A user with permission to create content and upload images. * * @var object