class JsonapiRequirements

Requirements for the JSON:API module.

Hierarchy

Expanded class hierarchy of JsonapiRequirements

File

core/modules/jsonapi/src/Hook/JsonapiRequirements.php, line 16

Namespace

Drupal\jsonapi\Hook
View source
class JsonapiRequirements {
    use StringTranslationTrait;
    public function __construct(ConfigFactoryInterface $configFactory, ModuleHandlerInterface $moduleHandler) {
    }
    
    /**
     * Implements hook_runtime_requirements().
     */
    public function runtime() : array {
        $requirements = [];
        $potential_conflicts = [
            'content_translation',
            'config_translation',
            'language',
        ];
        $should_warn = array_reduce($potential_conflicts, function ($should_warn, $module_name) {
            return $should_warn ?: $this->moduleHandler
                ->moduleExists($module_name);
        }, FALSE);
        if ($should_warn) {
            $requirements['jsonapi_multilingual_support'] = [
                'title' => $this->t('JSON:API multilingual support'),
                'value' => $this->t('Limited'),
                'severity' => REQUIREMENT_INFO,
                'description' => $this->t('Some multilingual features currently do not work well with JSON:API. See the <a href=":jsonapi-docs">JSON:API multilingual support documentation</a> for more information on the current status of multilingual support.', [
                    ':jsonapi-docs' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/translations',
                ]),
            ];
        }
        $requirements['jsonapi_revision_support'] = [
            'title' => $this->t('JSON:API revision support'),
            'value' => $this->t('Limited'),
            'severity' => REQUIREMENT_INFO,
            'description' => $this->t('Revision support is currently read-only and only for the "Content" and "Media" entity types in JSON:API. See the <a href=":jsonapi-docs">JSON:API revision support documentation</a> for more information on the current status of revision support.', [
                ':jsonapi-docs' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/revisions',
            ]),
        ];
        $requirements['jsonapi_read_only_mode'] = [
            'title' => $this->t('JSON:API allowed operations'),
            'value' => $this->t('Read-only'),
            'severity' => REQUIREMENT_INFO,
        ];
        if (!$this->configFactory
            ->get('jsonapi.settings')
            ->get('read_only')) {
            $requirements['jsonapi_read_only_mode']['value'] = $this->t('All (create, read, update, delete)');
            $requirements['jsonapi_read_only_mode']['description'] = $this->t('It is recommended to <a href=":configure-url">configure</a> JSON:API to only accept all operations if the site requires it. <a href=":docs">Learn more about securing your site with JSON:API.</a>', [
                ':docs' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/security-considerations',
                ':configure-url' => Url::fromRoute('jsonapi.settings')->toString(),
            ]);
        }
        return $requirements;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
JsonapiRequirements::runtime public function Implements hook_runtime_requirements().
JsonapiRequirements::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.