fix(CodingStandards): manual coding standards fixes

parent 1ab44a55
# 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.
......@@ -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;
}
}
......@@ -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);
}
......
......@@ -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',
......
......@@ -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
......
......@@ -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.
*/
......
......@@ -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.';
}
......@@ -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();
}
......
......@@ -28,6 +28,8 @@ class ConfigurableResourceType extends ResourceType {
protected $enhancerManager;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment