summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateu Aguiló Bosch2017-12-24 09:26:26 (GMT)
committerMateu Aguiló Bosch2017-12-24 09:26:26 (GMT)
commitc304e8f66c10ea578ce3e9ba78c930f1e9b37e20 (patch)
tree07696907e849331cf16e2ae6ef3ae15442d73ded
parent1ab44a5550c5558b72cd658ac6b7da97102e7097 (diff)
fix(CodingStandards): manual coding standards fixes
-rw-r--r--README.md7
-rw-r--r--jsonapi_extras.module2
-rw-r--r--phpcs.xml (renamed from phpcs.xml.dist)0
-rw-r--r--src/Form/JsonapiExtrasSettingsForm.php30
-rw-r--r--src/Form/JsonapiResourceConfigForm.php20
-rw-r--r--src/JsonapiResourceConfigListBuilder.php1
-rw-r--r--src/Normalizer/SchemataSchemaNormalizer.php2
-rw-r--r--src/Plugin/Validation/Constraint/DuplicateFieldConstraint.php7
-rw-r--r--src/Plugin/Validation/Constraint/DuplicateFieldConstraintValidator.php11
-rw-r--r--src/ResourceType/ConfigurableResourceType.php2
-rw-r--r--src/ResourceType/ConfigurableResourceTypeRepository.php4
-rw-r--r--tests/src/Functional/JsonExtrasApiFunctionalTest.php12
12 files changed, 82 insertions, 16 deletions
diff --git a/README.md b/README.md
index c58fe0d..0cdb9fd 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,8 @@
# JSON API Extras
-This module provides extra functionality on top of JSON API. You should not need this module to get an spec compliant JSON API, this module is to customize the output of JSON API.
+This module provides extra functionality on top of JSON API. You should not
+need this module to get an spec compliant JSON API, this module is to
+customize the output of JSON API.
This module adds the following features:
@@ -11,4 +13,5 @@ This module adds the following features:
- Lets you remove fields from the JSON API output.
TODO:
- * Auto calculate the dependency of the provider of the entity type and bundles in the configuration entity.
+ * Auto calculate the dependency of the provider of the entity type and
+ bundles in the configuration entity.
diff --git a/jsonapi_extras.module b/jsonapi_extras.module
index f26e487..ad05485 100644
--- a/jsonapi_extras.module
+++ b/jsonapi_extras.module
@@ -15,7 +15,7 @@ function jsonapi_extras_help($route_name, RouteMatchInterface $route_match) {
case 'entity.jsonapi_resource_config.collection':
$output = '';
$output .= '<p>' . t('The following table shows the list of JSON API resources available.') . '</p>';
- $output .= '<p>' . t('Use the overwrite operation to overwrite a resource\'s configuration. You can revert back to the default configuration using the revert operation.') . '</p>';
+ $output .= '<p>' . t("Use the overwrite operation to overwrite a resource's configuration. You can revert back to the default configuration using the revert operation.") . '</p>';
return $output;
}
}
diff --git a/phpcs.xml.dist b/phpcs.xml
index 707f10b..707f10b 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml
diff --git a/src/Form/JsonapiExtrasSettingsForm.php b/src/Form/JsonapiExtrasSettingsForm.php
index 98e3bb0..7fc5845 100644
--- a/src/Form/JsonapiExtrasSettingsForm.php
+++ b/src/Form/JsonapiExtrasSettingsForm.php
@@ -2,14 +2,42 @@
namespace Drupal\jsonapi_extras\Form;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Routing\RouteBuilder;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure JSON API settings for this site.
*/
class JsonapiExtrasSettingsForm extends ConfigFormBase {
+ protected $routerBuilder;
+
+ /**
+ * Constructs a \Drupal\system\ConfigFormBase object.
+ *
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The factory for configuration objects.
+ * @param \Drupal\Core\Routing\RouteBuilder $router_builder
+ * The router builder to rebuild menus after saving config entity.
+ */
+ public function __construct(ConfigFactoryInterface $config_factory, RouteBuilder $router_builder) {
+ parent::__construct($config_factory);
+ $this->routerBuilder = $router_builder;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('config.factory'),
+ $container->get('router.builder')
+ );
+ }
+
/**
* {@inheritdoc}
*/
@@ -64,7 +92,7 @@ class JsonapiExtrasSettingsForm extends ConfigFormBase {
->save();
// Rebuild the router.
- \Drupal::service('router.builder')->setRebuildNeeded();
+ $this->routerBuilder->setRebuildNeeded();
parent::submitForm($form, $form_state);
}
diff --git a/src/Form/JsonapiResourceConfigForm.php b/src/Form/JsonapiResourceConfigForm.php
index dc1f175..a0c7f33 100644
--- a/src/Form/JsonapiResourceConfigForm.php
+++ b/src/Form/JsonapiResourceConfigForm.php
@@ -73,6 +73,8 @@ class JsonapiResourceConfigForm extends EntityForm {
protected $request;
/**
+ * The typed config manager.
+ *
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
@@ -93,7 +95,9 @@ class JsonapiResourceConfigForm extends EntityForm {
* @param \Drupal\Core\Config\ImmutableConfig $config
* The config instance.
* @param \Symfony\Component\HttpFoundation\Request $request
+ * The HTTP request.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
+ * The 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, TypedConfigManagerInterface $typed_config_manager) {
$this->bundleInfo = $bundle_info;
@@ -308,12 +312,12 @@ class JsonapiResourceConfigForm extends EntityForm {
$markup = '';
$markup .= '<dl>';
- $markup .= '<dt>' . t('Disabled') . '</dt>';
- $markup .= '<dd>' . t('Check this if you want to disable this field completely. Disabling required fields will cause problems when writing to the resource.') . '</dd>';
- $markup .= '<dt>' . t('Alias') . '</dt>';
- $markup .= '<dd>' . t('Overrides the field name with a custom name. Example: Change "field_tags" to "tags".') . '</dd>';
- $markup .= '<dt>' . t('Enhancer') . '</dt>';
- $markup .= '<dd>' . t('Select an enhancer to manipulate the public output coming in and out.') . '</dd>';
+ $markup .= '<dt>' . $this->t('Disabled') . '</dt>';
+ $markup .= '<dd>' . $this->t('Check this if you want to disable this field completely. Disabling required fields will cause problems when writing to the resource.') . '</dd>';
+ $markup .= '<dt>' . $this->t('Alias') . '</dt>';
+ $markup .= '<dd>' . $this->t('Overrides the field name with a custom name. Example: Change "field_tags" to "tags".') . '</dd>';
+ $markup .= '<dt>' . $this->t('Enhancer') . '</dt>';
+ $markup .= '<dd>' . $this->t('Select an enhancer to manipulate the public output coming in and out.') . '</dd>';
$markup .= '</dl>';
$overrides_form['overrides']['fields']['info'] = [
'#markup' => $markup,
@@ -488,7 +492,9 @@ class JsonapiResourceConfigForm extends EntityForm {
$bundles = [];
$bundle_info = $this->bundleInfo->getBundleInfo($entity_type_id);
foreach ($bundle_info as $bundle_id => $info) {
- $bundles[$bundle_id] = $info['translatable'] ? $this->t($info['label']) : $info['label'];
+ $bundles[$bundle_id] = $info['translatable']
+ ? $this->t('%label', ['%label' => $info['label']])
+ : $info['label'];
}
$form['bundle_wrapper']['_bundle_id'] = [
'#type' => 'select',
diff --git a/src/JsonapiResourceConfigListBuilder.php b/src/JsonapiResourceConfigListBuilder.php
index 12e89ca..5d22f41 100644
--- a/src/JsonapiResourceConfigListBuilder.php
+++ b/src/JsonapiResourceConfigListBuilder.php
@@ -35,6 +35,7 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder {
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
+ * The storage.
* @param \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository $resource_type_repository
* The JSON API configurable resource type repository.
* @param \Drupal\Core\Config\ImmutableConfig $config
diff --git a/src/Normalizer/SchemataSchemaNormalizer.php b/src/Normalizer/SchemataSchemaNormalizer.php
index f697b9b..247fa17 100644
--- a/src/Normalizer/SchemataSchemaNormalizer.php
+++ b/src/Normalizer/SchemataSchemaNormalizer.php
@@ -18,6 +18,8 @@ class SchemataSchemaNormalizer extends SchemataJsonSchemaSchemataSchemaNormalize
protected $resourceTypeRepository;
/**
+ * Constructs a SchemataSchemaNormalizer object.
+ *
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository
* A resource repository.
*/
diff --git a/src/Plugin/Validation/Constraint/DuplicateFieldConstraint.php b/src/Plugin/Validation/Constraint/DuplicateFieldConstraint.php
index cb1cd9b..1bd0ad7 100644
--- a/src/Plugin/Validation/Constraint/DuplicateFieldConstraint.php
+++ b/src/Plugin/Validation/Constraint/DuplicateFieldConstraint.php
@@ -5,6 +5,8 @@ namespace Drupal\jsonapi_extras\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
+ * The constraint object.
+ *
* @Constraint(
* id = "jsonapi_extras__duplicate_field",
* label = @Translation("Duplicate field", context = "Validation")
@@ -12,6 +14,11 @@ use Symfony\Component\Validator\Constraint;
*/
class DuplicateFieldConstraint extends Constraint {
+ /**
+ * The error message for the constraint.
+ *
+ * @var string
+ */
public $message = 'The override must be unique.';
}
diff --git a/src/Plugin/Validation/Constraint/DuplicateFieldConstraintValidator.php b/src/Plugin/Validation/Constraint/DuplicateFieldConstraintValidator.php
index c1032de..657c91e 100644
--- a/src/Plugin/Validation/Constraint/DuplicateFieldConstraintValidator.php
+++ b/src/Plugin/Validation/Constraint/DuplicateFieldConstraintValidator.php
@@ -7,10 +7,13 @@ use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
+ * The validator.
*/
class DuplicateFieldConstraintValidator extends ConstraintValidator {
/**
+ * The entity type manager.
+ *
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
@@ -49,7 +52,8 @@ class DuplicateFieldConstraintValidator extends ConstraintValidator {
->addViolation();
}
}
- // Now compare the overrides with the default names to validate no dupes exist.
+ // Now compare the overrides with the default names to validate no dupes
+ // exist.
foreach ($overrides as $field => $override) {
if (array_key_exists($override, $resourceFields)) {
$this->context->buildViolation($constraint->message)
@@ -68,7 +72,10 @@ class DuplicateFieldConstraintValidator extends ConstraintValidator {
}
if ($resource_type->get('resourceType') == $entity_data['resourceType']) {
- $this->context->buildViolation('There is already resource (@name) with this resource type.', ['@name' => $resource_type->id()])
+ $this->context->buildViolation(
+ 'There is already resource (@name) with this resource type.',
+ ['@name' => $resource_type->id()]
+ )
->atPath('resourceType')
->addViolation();
}
diff --git a/src/ResourceType/ConfigurableResourceType.php b/src/ResourceType/ConfigurableResourceType.php
index eb4aba3..0917547 100644
--- a/src/ResourceType/ConfigurableResourceType.php
+++ b/src/ResourceType/ConfigurableResourceType.php
@@ -28,6 +28,8 @@ class ConfigurableResourceType extends ResourceType {
protected $enhancerManager;
/**
+ * The configuration factory.
+ *
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
diff --git a/src/ResourceType/ConfigurableResourceTypeRepository.php b/src/ResourceType/ConfigurableResourceTypeRepository.php
index ae8b1c4..9c3cbad 100644
--- a/src/ResourceType/ConfigurableResourceTypeRepository.php
+++ b/src/ResourceType/ConfigurableResourceTypeRepository.php
@@ -30,11 +30,15 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
protected $enhancerManager;
/**
+ * The configuration factory.
+ *
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
+ * A list of resource types.
+ *
* @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType[]
*/
protected $resourceTypes;
diff --git a/tests/src/Functional/JsonExtrasApiFunctionalTest.php b/tests/src/Functional/JsonExtrasApiFunctionalTest.php
index 7e60cba..3b612f2 100644
--- a/tests/src/Functional/JsonExtrasApiFunctionalTest.php
+++ b/tests/src/Functional/JsonExtrasApiFunctionalTest.php
@@ -13,6 +13,8 @@ use Drupal\user\Entity\User;
use Symfony\Component\Routing\Route;
/**
+ * The test class for the main functionality.
+ *
* @group jsonapi_extras
*/
class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
@@ -59,12 +61,16 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
// 1. Make sure the api root is under '/api' and not '/jsonapi'.
/** @var \Symfony\Component\Routing\RouteCollection $route_collection */
- $route_collection = \Drupal::service('router.route_provider')->getRoutesByPattern('/api');
- $this->assertInstanceOf(Route::class, $route_collection->get('jsonapi.resource_list'));
+ $route_collection = \Drupal::service('router.route_provider')
+ ->getRoutesByPattern('/api');
+ $this->assertInstanceOf(
+ Route::class, $route_collection->get('jsonapi.resource_list')
+ );
$this->drupalGet('/jsonapi');
$this->assertSession()->statusCodeEquals(404);
- // 2. Make sure the count is included in collections. This also tests the overridden paths.
+ // 2. Make sure the count is included in collections. This also tests the
+ // overridden paths.
$output = Json::decode($this->drupalGet('/api/articles'));
$this->assertSame($num_articles, (int) $output['meta']['count']);
$this->assertSession()->statusCodeEquals(200);