summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateu Aguiló Bosch2017-09-14 19:46:08 +0200
committerMateu Aguiló Bosch2017-09-14 19:46:08 +0200
commit6668c74ce2a96268a83fea39e6c712acf36d9c88 (patch)
tree04e0043317f3a2fb8f0c929df390459ccb10d434
parent95eecfdc9eb025ddbf5f7a2d6622798d060442af (diff)
fix(Form): Disable validation for 8.3 or less (#2908725 by e0ipso)
-rw-r--r--src/Form/JsonapiResourceConfigForm.php24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/Form/JsonapiResourceConfigForm.php b/src/Form/JsonapiResourceConfigForm.php
index 591026b..f8c2dad 100644
--- a/src/Form/JsonapiResourceConfigForm.php
+++ b/src/Form/JsonapiResourceConfigForm.php
@@ -3,6 +3,7 @@
namespace Drupal\jsonapi_extras\Form;
use Drupal\Core\Config\ImmutableConfig;
+use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityFieldManager;
use Drupal\Core\Entity\EntityForm;
@@ -72,6 +73,11 @@ class JsonapiResourceConfigForm extends EntityForm {
protected $request;
/**
+ * @var \Drupal\Core\Config\TypedConfigManagerInterface
+ */
+ protected $typedConfigManager;
+
+ /**
* JsonapiResourceConfigForm constructor.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info
@@ -87,8 +93,9 @@ class JsonapiResourceConfigForm extends EntityForm {
* @param \Drupal\Core\Config\ImmutableConfig $config
* The config instance.
* @param \Symfony\Component\HttpFoundation\Request $request
+ * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
*/
- public function __construct(EntityTypeBundleInfoInterface $bundle_info, ResourceTypeRepository $resource_type_repository, EntityFieldManager $field_manager, EntityTypeRepositoryInterface $entity_type_repository, ResourceFieldEnhancerManager $enhancer_manager, ImmutableConfig $config, Request $request) {
+ public function __construct(EntityTypeBundleInfoInterface $bundle_info, ResourceTypeRepository $resource_type_repository, EntityFieldManager $field_manager, EntityTypeRepositoryInterface $entity_type_repository, ResourceFieldEnhancerManager $enhancer_manager, ImmutableConfig $config, Request $request, TypedConfigManagerInterface $typed_config_manager) {
$this->bundleInfo = $bundle_info;
$this->resourceTypeRepository = $resource_type_repository;
$this->fieldManager = $field_manager;
@@ -96,6 +103,7 @@ class JsonapiResourceConfigForm extends EntityForm {
$this->enhancerManager = $enhancer_manager;
$this->config = $config;
$this->request = $request;
+ $this->typedConfigManager = $typed_config_manager;
}
/**
@@ -109,7 +117,8 @@ class JsonapiResourceConfigForm extends EntityForm {
$container->get('entity_type.repository'),
$container->get('plugin.manager.resource_field_enhancer'),
$container->get('config.factory')->get('jsonapi_extras.settings'),
- $container->get('request_stack')->getCurrentRequest()
+ $container->get('request_stack')->getCurrentRequest(),
+ $container->get('config.typed')
);
}
@@ -165,11 +174,14 @@ class JsonapiResourceConfigForm extends EntityForm {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
- /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager */
- $typed_config_manager = \Drupal::service('config.typed');
- $typed_config = $typed_config_manager->createFromNameAndData($this->entity->id(), $this->entity->toArray());
+ if (!method_exists($this->typedConfigManager, 'createFromNameAndData')) {
+ // Versions of Drupal before 8.4 have poor support for constraints. In
+ // those scenarios we don't validate the form submission.
+ return;
+ }
+ $typed_config = $this->typedConfigManager
+ ->createFromNameAndData($this->entity->id(), $this->entity->toArray());
$constraints = $typed_config->validate();
-
/** @var \Symfony\Component\Validator\ConstraintViolation $violation */
foreach ($constraints as $violation) {
$form_path = str_replace('.', '][', $violation->getPropertyPath());