diff --git a/collect.routing.yml b/collect.routing.yml index 3b65831..7a04e67 100644 --- a/collect.routing.yml +++ b/collect.routing.yml @@ -96,7 +96,7 @@ collect.create_entity: _controller: 'Drupal\collect\Controller\CreateEntityController::createEntity' requirements: _custom_access: 'Drupal\collect\Controller\CreateEntityController::checkAccess' - _csrf_token: 'TRUE' + _csrf_token: 'true' collect.settings: path: '/admin/config/services/collect' @@ -112,4 +112,4 @@ collect.generate_page: _controller: 'Drupal\collect\Controller\GenerateWebPageController::generatePage' requirements: _custom_access: 'Drupal\collect\Controller\GenerateWebPageController::checkAccess' - _csrf_token: 'TRUE' + _csrf_token: 'true' diff --git a/src/Controller/GenerateWebPageController.php b/src/Controller/GenerateWebPageController.php index cbdea1b..8b7f66b 100644 --- a/src/Controller/GenerateWebPageController.php +++ b/src/Controller/GenerateWebPageController.php @@ -67,7 +67,6 @@ class GenerateWebPageController extends ControllerBase { public function checkAccess(CollectContainerInterface $collect_container) { $access = AccessResult::allowedIfHasPermission(\Drupal::currentUser(), 'administer collect'); $schema = $this->schemaManager->createInstanceFromUri($collect_container->getSchemaUri()); - $has_fetch_url_plugin = $schema instanceof FetchUrlSchema ? TRUE : FALSE; - return $access->andIf($has_fetch_url_plugin ? AccessResult::allowed() : AccessResult::forbidden()); + return $access->andIf(AccessResult::allowedIf($schema instanceof FetchUrlSchema)); } } diff --git a/src/Form/FetchUrlForm.php b/src/Form/FetchUrlForm.php index 06a76eb..ab42809 100644 --- a/src/Form/FetchUrlForm.php +++ b/src/Form/FetchUrlForm.php @@ -7,6 +7,7 @@ namespace Drupal\collect\Form; use Drupal\collect\Entity\Container; +use Drupal\collect\Schema\SchemaManagerInterface; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -32,11 +33,19 @@ class FetchUrlForm extends FormBase { protected $httpClient; /** + * The injected schema plugin manager. + * + * @var \Drupal\collect\Schema\SchemaManagerInterface + */ + protected $schemaManager; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( - $container->get('http_client') + $container->get('http_client'), + $container->get('plugin.manager.collect.schema') ); } @@ -46,8 +55,9 @@ class FetchUrlForm extends FormBase { * @param \Drupal\Core\Http\Client $http_client * The http client. */ - public function __construct(Client $http_client) { + public function __construct(Client $http_client, SchemaManagerInterface $schema_manager) { $this->httpClient = $http_client; + $this->schemaManager = $schema_manager; } /** @@ -167,7 +177,11 @@ class FetchUrlForm extends FormBase { ->pager(1) ->execute(); - if (empty($ids)) { + $is_container_revision = FALSE; + if ($this->schemaManager->loadConfigByUri($container->getSchemaUri())) { + $is_container_revision = $this->schemaManager->loadConfigByUri($container->getSchemaUri())->get('container_revision'); + } + if (empty($ids) || !$is_container_revision) { // Save new container. $container->save(); } diff --git a/src/Plugin/collect/Schema/FetchUrlSchema.php b/src/Plugin/collect/Schema/FetchUrlSchema.php index 0bd48b2..c3b46d6 100644 --- a/src/Plugin/collect/Schema/FetchUrlSchema.php +++ b/src/Plugin/collect/Schema/FetchUrlSchema.php @@ -47,31 +47,27 @@ class FetchUrlSchema extends SchemaBase { return; } $output = array(); - $output['request-headers'] = array( + $output['request_headers'] = array( '#type' => 'table', '#header' => [$this->t('Request headers'), NULL], - '#empty' => $this->t('There are no data.'), - '#prefix' => '