Commit a3faee31 authored by Sumit Madan's avatar Sumit Madan Committed by Saul Willers
Browse files

Issue #2503105 by sumitmadan: Display webform tab only on webform enabled content type nodes

parent 666a5aa7
Loading
Loading
Loading
Loading
+48 −0
Changes for src/Access/WebformNodeAccessCheck.php: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains \Drupal\webform\Access\WebformNodeAccessCheck.
 */

namespace Drupal\webform\Access;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\Routing\Route;

/**
 * Determines access to routes based on webform enabled content type.
 */
class WebformNodeAccessCheck implements AccessInterface {
  /**
   * The node storage.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected $nodeStorage;

  /**
   * Constructs a new WebformNodeAccessCheck.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->nodeStorage = $entity_manager->getStorage('node');
  }

  /**
   * {@inheritdoc}
   */
  public function access(Route $route, AccountInterface $account, NodeInterface $node = NULL) {
    if ($node->bundle() && \Drupal::config('webform.settings')->get('node_' . $node->bundle())) {
      return AccessResult::allowed();
    }
    return AccessResult::forbidden();
  }

}
+1 −1
Changes for webform.routing.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ webform.component_delete_form:
  requirements:
    _permission: 'administer site configuration'

# @todo Only show on webform enabled node types
entity.node.webform:
  path: '/node/{node}/webform'
  defaults:
@@ -53,5 +52,6 @@ entity.node.webform:
  requirements:
    # @todo This needs to call/replicate webform_node_update_access().
    _permission: 'edit webform components'
    _access_check_webform: 'TRUE'
  options:
    _node_operation_route: TRUE
+5 −0
Changes for webform.services.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
services:
  webform.webform_node:
    class: Drupal\webform\Access\WebformNodeAccessCheck
    arguments: ['@entity.manager']
    tags:
      - { name: access_check, applies_to: _access_check_webform }
  plugin.manager.webform.component:
    class: Drupal\webform\ComponentManager
    parent: default_plugin_manager