diff --git a/modules/rh_node/src/Plugin/RabbitHoleEntityPlugin/Node.php b/modules/rh_node/src/Plugin/RabbitHoleEntityPlugin/Node.php index d14276c..e65edb8 100644 --- a/modules/rh_node/src/Plugin/RabbitHoleEntityPlugin/Node.php +++ b/modules/rh_node/src/Plugin/RabbitHoleEntityPlugin/Node.php @@ -15,7 +15,7 @@ use Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginBase; * @RabbitHoleEntityPlugin( * id = "rh_node", * label = @Translation("Node"), - * entity_type = "node" + * entityType = "node" * ) */ class Node extends RabbitHoleEntityPluginBase { diff --git a/modules/rh_node/src/Tests/BehaviorSettingsFormAlterationsTest.php b/modules/rh_node/src/Tests/BehaviorSettingsFormAlterationsTest.php index c53224f..4efc432 100644 --- a/modules/rh_node/src/Tests/BehaviorSettingsFormAlterationsTest.php +++ b/modules/rh_node/src/Tests/BehaviorSettingsFormAlterationsTest.php @@ -40,10 +40,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { */ protected function setUp() { parent::setUp(); - /** - * @todo These tests should be expanded for users with different types - * of permissions - */ + // TODO: These tests should be expanded for users with different types of + // permissions. $this->user = $this->drupalCreateUser(array( 'bypass node access', 'administer content types', )); @@ -53,6 +51,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { } /** + * Test that bundle form of new content type contains rabbit hole settings. + * * Test that the content type form of a newly created content type contains * the expected fields. */ @@ -71,6 +71,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { } /** + * Test that saving bundle changes creates a settings config key for bundle. + * * Test that saving changes to a content type form creates an appropriate * behavior settings config key. */ @@ -93,6 +95,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { } /** + * Test that bundle form with a configured bundle behaviour loads config. + * * Test that a content type form of a content type with a configured behavior * properly loads configuration. */ @@ -117,8 +121,10 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { } /** - * Test that saving changes to a content type form which already has configured - * rabbit hole behavior settings changes the existing key. + * Test new changes to bundle with existing rabbit hole settings changes key. + * + * Test that saving changes to a content type form which already has + * configured rabbit hole behavior settings changes the existing key. */ public function testContentTypeFormSave() { $test_content_type_id = $this->createTestContentType(); @@ -148,6 +154,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { } /** + * Test that we can save settings for node that did not previously have them. + * * Test that an existing node that previously didn't have settings will have * settings saved when the node form is saved. */ @@ -185,8 +193,7 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { } /** - * Test that when a node form is loaded it defaults to using the bundle - * configuration. + * Test that when a node form is loaded it defaults the bundle configuration. */ public function testDefaultNodeSettingsLoad() { $this->createTestContentType(); @@ -203,8 +210,7 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { } /** - * Test that a node form correctly loads previously saved rabbit hole behavior - * settings. + * Test that a node form correctly loads previously saved behavior settings. */ public function testExistingNodeSettingsLoad() { $this->createTestContentType(); @@ -220,7 +226,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { /** * Create a content type for testing. * - * @return string The content type ID + * @return string + * The content type ID. */ private function createTestContentType() { $node_type = NodeType::create( @@ -236,7 +243,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { /** * Create a node for testing. * - * @return integer The node ID + * @return int + * The node ID. */ private function createTestNode($action = '') { $node = Node::create( @@ -276,7 +284,8 @@ class BehaviorSettingsFormAlterationsTest extends WebTestBase { /** * Load the node form for the test node with the given ID. * - * @param $test_node_id The ID of the test node + * @param string $test_node_id + * The ID of the test node. */ private function loadNodeFormForTestNode($test_node_id) { $this->drupalLogin($this->user); diff --git a/modules/rh_node/src/Tests/InvocationTest.php b/modules/rh_node/src/Tests/InvocationTest.php index fdd923d..2b6d271 100644 --- a/modules/rh_node/src/Tests/InvocationTest.php +++ b/modules/rh_node/src/Tests/InvocationTest.php @@ -40,8 +40,7 @@ class InvocationTest extends WebTestBase { } /** - * Test that a fresh node with a fresh content type takes the default action - * (displays the page). + * Test that a fresh node with a fresh content type takes the default action. */ public function testNodeDefaults() { $type = $this->createTestNodeType(); @@ -51,8 +50,7 @@ class InvocationTest extends WebTestBase { } /** - * Test that a node with action not set or set to bundle_default will default - * to the bundle action. + * Test action not set or set to bundle_default will default to bundle action. */ public function testDefaultToBundle() { $type = $this->createTestNodeType('access_denied'); @@ -66,8 +64,7 @@ class InvocationTest extends WebTestBase { } /** - * Test that a node set to access_denied overrides the bundle and returns a - * 403 response. + * Test that a node set to access_denied returns a 403 response. */ public function testAccessDenied() { $type = $this->createTestNodeType(); @@ -77,8 +74,7 @@ class InvocationTest extends WebTestBase { } /** - * Test that a node set to display_page overrides the bundle and returns a - * 200 response. + * Test that a node set to display_page returns a 200 response. */ public function testDisplayPage() { $type = $this->createTestNodeType('access_denied'); @@ -88,7 +84,7 @@ class InvocationTest extends WebTestBase { } /** - * + * TODO. */ public function testUrlRedirects() { $type = $this->createTestNodeType('access_denied'); @@ -116,8 +112,7 @@ class InvocationTest extends WebTestBase { public function testCodeRedirect() {} /** - * Test that a node set to page_not_found overrides the bundle and returns a - * 404 response. + * Test that a node set to page_not_found overrides returns a 404. */ public function testPageNotFound() { $type = $this->createTestNodeType(); @@ -127,7 +122,7 @@ class InvocationTest extends WebTestBase { } /** - * + * TODO. */ private function createTestNodeType($action = NULL) { $node_type = NodeType::create( @@ -145,7 +140,7 @@ class InvocationTest extends WebTestBase { } /** - * + * TODO. */ private function createTestNodeOfType($node_type_id = self::TEST_CONTENT_TYPE_ID, $action = NULL) { $node = Node::create( diff --git a/modules/rh_user/src/Plugin/RabbitHoleEntityPlugin/User.php b/modules/rh_user/src/Plugin/RabbitHoleEntityPlugin/User.php index d0826ae..86bbf23 100644 --- a/modules/rh_user/src/Plugin/RabbitHoleEntityPlugin/User.php +++ b/modules/rh_user/src/Plugin/RabbitHoleEntityPlugin/User.php @@ -15,7 +15,7 @@ use Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginBase; * @RabbitHoleEntityPlugin( * id = "rh_user", * label = @Translation("Node"), - * entity_type = "user" + * entityType = "user" * ) */ class User extends RabbitHoleEntityPluginBase { diff --git a/src/Annotation/RabbitHoleEntityPlugin.php b/src/Annotation/RabbitHoleEntityPlugin.php index 0e57ad5..7093ec4 100644 --- a/src/Annotation/RabbitHoleEntityPlugin.php +++ b/src/Annotation/RabbitHoleEntityPlugin.php @@ -40,6 +40,6 @@ class RabbitHoleEntityPlugin extends Plugin { * * @var string */ - public $entity_type; + public $entityType; } diff --git a/src/BehaviorInvoker.php b/src/BehaviorInvoker.php index 2d0c4f2..26199a5 100644 --- a/src/BehaviorInvoker.php +++ b/src/BehaviorInvoker.php @@ -66,12 +66,13 @@ class BehaviorInvoker implements BehaviorInvokerInterface { /** * Invoke a rabbit hole behavior based on an entity's configuration. * - * @note This assumes the entity is configured for use with Rabbit Hole - if - * you pass an entity to this method and it does not have a rabbit hole - * plugin it will use the defaults! - * @note This method can be triggered with a response if any plugins need - * it but this actually has no effect right now. Left it in because it - * might be useful. + * This assumes the entity is configured for use with Rabbit Hole - if you + * pass an entity to this method and it does not have a rabbit hole plugin it + * will use the defaults! + * + * This method can be triggered with a response if any plugins need it but + * this actually has no effect right now. Left it in because it might be + * useful. */ public function processEntity($entity, Response $current_response = NULL) { @@ -103,11 +104,10 @@ class BehaviorInvoker implements BehaviorInvokerInterface { } /** - * Load a list of entity IDs supported by rabbit hole based on available - * plugins. + * Load a list of entity IDs supported by rabbit hole given available plugins. * * @return array - * An array of string entity ids + * An array of string entity ids. */ public function getPossibleEntityTypeKeys() { $entity_type_keys = array(); @@ -118,12 +118,15 @@ class BehaviorInvoker implements BehaviorInvokerInterface { } /** + * An entity's rabbit hole configuration, or the default if it does not exist. + * * Return an entity's rabbit hole configuration or, failing that, the default * configuration for the bundle (which itself will call the base default * configuration if necessary). * - * @return array An array of values from the entity's fields matching the - * base properties added by rabbit hole + * @return array + * An array of values from the entity's fields matching the base properties + * added by rabbit hole. */ private function getRabbitHoleValuesForEntity(ContentEntityBase $entity) { $field_keys = array_keys($this->rhEntityExtender->getGeneralExtraFields()); diff --git a/src/BehaviorSettingsInterface.php b/src/BehaviorSettingsInterface.php index f4b7d46..3c2cd18 100644 --- a/src/BehaviorSettingsInterface.php +++ b/src/BehaviorSettingsInterface.php @@ -13,19 +13,20 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; * Provides an interface for defining Behavior settings entities. */ interface BehaviorSettingsInterface extends ConfigEntityInterface { - // Add get/set methods for your configuration properties here. + /** * Set the configured action. * * @param string $action - * The action to save + * The action to save. */ public function setAction($action); /** * Get the configured action. * - * @return string The action id + * @return string + * The action id. */ public function getAction(); @@ -33,14 +34,16 @@ interface BehaviorSettingsInterface extends ConfigEntityInterface { * Set whether overrides are allowed if this is for a bundle. * * @param int $allow_override - * 0 (N/A), 1 (Allow) or 2 (Disallow) + * 0 (N/A), 1 (Allow), or 2 (Disallow). */ public function setAllowOverride($allow_override); /** * Get whether overrides are allowed if this is for a bundle. * - * @return integer + * @return int + * Whether overrides are allowed if this is for a bundle. 0 (N/A), 1 + * (Allow), or 2 (Disallow). */ public function getAllowOverride(); @@ -48,7 +51,7 @@ interface BehaviorSettingsInterface extends ConfigEntityInterface { * Set the redirect code if action is redirect. * * @param int $redirect_code - * The redirect code (0 for N/A) + * The redirect code (0 for N/A). */ public function setRedirectCode($redirect_code); @@ -61,14 +64,15 @@ interface BehaviorSettingsInterface extends ConfigEntityInterface { * Set the redirect path if action is redirect. * * @param string $redirect_path - * The redirect path + * The redirect path. */ public function setRedirectPath($redirect_path); /** * Get the redirect path if action is redirect. * - * @return string The redirect path + * @return string + * The redirect path. */ public function getRedirectPath(); diff --git a/src/BehaviorSettingsManager.php b/src/BehaviorSettingsManager.php index 759c4f6..9399c3e 100644 --- a/src/BehaviorSettingsManager.php +++ b/src/BehaviorSettingsManager.php @@ -22,13 +22,13 @@ class BehaviorSettingsManager implements BehaviorSettingsManagerInterface { * * @var Drupal\Core\Config\ConfigFactory */ - protected $config_factory; + protected $configFactory; /** * Constructor. */ public function __construct(ConfigFactory $config_factory) { - $this->config_factory = $config_factory; + $this->configFactory = $config_factory; } /** @@ -58,14 +58,14 @@ class BehaviorSettingsManager implements BehaviorSettingsManagerInterface { public function loadBehaviorSettingsAsConfig($entity_type_id, $entity_id = NULL) { - $actual = $this->config_factory->get( + $actual = $this->configFactory->get( 'rabbit_hole.behavior_settings.' . $this->generateBehaviorSettingsFullId($entity_type_id, $entity_id)); if (!$actual->isNew()) { return $actual; } else { - return $this->config_factory + return $this->configFactory ->get('rabbit_hole.behavior_settings.default'); } } @@ -76,7 +76,7 @@ class BehaviorSettingsManager implements BehaviorSettingsManagerInterface { public function loadBehaviorSettingsAsEditableConfig($entity_type_id, $entity_id, $is_bundle = FALSE) { - $actual = $this->config_factory->getEditable( + $actual = $this->configFactory->getEditable( 'rabbit_hole.behavior_settings.' . $this->generateBehaviorSettingsFullId($entity_type_id, $entity_id, $is_bundle @@ -90,11 +90,12 @@ class BehaviorSettingsManager implements BehaviorSettingsManagerInterface { * Generate a full ID based on entity type label, bundle label and entity id. * * @param string $entity_type_id - * The entity type (e.g. node) as a string + * The entity type (e.g. node) as a string. * @param string $entity_id - * The entity ID as a string + * The entity ID as a string. * - * @return string The full id appropriate for a BehaviorSettings config entity + * @return string + * The full id appropriate for a BehaviorSettings config entity. */ private function generateBehaviorSettingsFullId($entity_type_id, $entity_id = '') { diff --git a/src/BehaviorSettingsManagerInterface.php b/src/BehaviorSettingsManagerInterface.php index 34e550e..696b04e 100644 --- a/src/BehaviorSettingsManagerInterface.php +++ b/src/BehaviorSettingsManagerInterface.php @@ -17,37 +17,44 @@ interface BehaviorSettingsManagerInterface { /** * Save behavior settings for an entity or bundle. * - * @param array settings The settings for the BehaviorSettings entity + * @param array $settings + * The settings for the BehaviorSettings entity. * @param string $entity_type_id - * The entity type (e.g. node) as a string + * The entity type (e.g. node) as a string. * @param string $entity_id - * The entity ID as a string + * The entity ID as a string. */ public function saveBehaviorSettings($settings, $entity_type_id, $entity_id); /** + * Load behaviour settings for an entity or bundle, or load the defaults. + * * Load rabbit hole behaviour settings appropriate to the given config or * default settings if not available. * * @param string $entity_type_label - * The entity type (e.g. node) as a string + * The entity type (e.g. node) as a string. * @param string $entity_id - * The entity ID as a string + * The entity ID as a string. * - * @return \Drupal\Core\Config\ImmutableConfig The BehaviorSettings Config object + * @return \Drupal\Core\Config\ImmutableConfig + * The BehaviorSettings Config object. */ public function loadBehaviorSettingsAsConfig($entity_type_label, $entity_id); /** - * Load editable rabbit hole behaviour settings appropriate to the given config - * or NULL if not available. + * Load behaviour settings for an entity or bundle, or return NULL. + * + * Load editable rabbit hole behaviour settings appropriate to the given + * config or NULL if not available. * * @param string $entity_type_label - * The entity type (e.g. node) as a string + * The entity type (e.g. node) as a string. * @param string $entity_id - * The entity ID as a string + * The entity ID as a string. * - * @return \Drupal\Core\Config\ImmutableConfig|null The BehaviorSettings Config object + * @return \Drupal\Core\Config\ImmutableConfig|null + * The BehaviorSettings Config object or NULL if it does not exist. */ public function loadBehaviorSettingsAsEditableConfig($entity_type_label, $entity_id); diff --git a/src/EventSubscriber/RabbitHoleSubscriber.php b/src/EventSubscriber/RabbitHoleSubscriber.php index c7d1d9c..56f6e57 100644 --- a/src/EventSubscriber/RabbitHoleSubscriber.php +++ b/src/EventSubscriber/RabbitHoleSubscriber.php @@ -42,21 +42,27 @@ class RabbitHoleSubscriber implements EventSubscriberInterface { } /** - * This method is called whenever the kernel.request event is - * dispatched. It invokes a rabbit hole behavior on an entity in - * the request if applicable. + * A method to be called whenever a kernel.request event is dispatched. * - * @param GetResponseEvent $event + * It invokes a rabbit hole behavior on an entity in the request if + * applicable. + * + * @param \Symfony\Component\EventDispatcher\Event $event + * The event triggered by the request. */ public function onRequest(Event $event) { return $this->processEvent($event); } /** - * This method is called whenever a kernel.response event is dispatched. Like - * the onRequest event, it invokes a rabbit hole behavior on an entity in + * A method to be called whenever a kernel.response event is dispatched. + * + * Like the onRequest event, it invokes a rabbit hole behavior on an entity in * the request if possible. Unlike the onRequest event, it also passes in a * response. + * + * @param \Symfony\Component\EventDispatcher\Event $event + * The event triggered by the response. */ public function onResponse(Event $event) { return $this->processEvent($event); @@ -64,6 +70,9 @@ class RabbitHoleSubscriber implements EventSubscriberInterface { /** * Process events generically invoking rabbit hole behaviors if necessary. + * + * @param \Symfony\Component\EventDispatcher\Event $event + * The event to process. */ private function processEvent(Event $event) { // Don't process events with HTTP exceptions - those have either been thrown diff --git a/src/FormManglerService.php b/src/FormManglerService.php index a6c70d3..514feb3 100644 --- a/src/FormManglerService.php +++ b/src/FormManglerService.php @@ -39,16 +39,16 @@ class FormManglerService { public function __construct( EntityTypeManager $etm, EntityTypeBundleInfo $etbi, - RabbitHoleBehaviorPluginManager $behaviorPluginManager, - RabbitHoleEntityPluginManager $entityPluginManager, - BehaviorSettingsManager $behaviorSettingsManager, + RabbitHoleBehaviorPluginManager $behavior_plugin_manager, + RabbitHoleEntityPluginManager $entity_plugin_manager, + BehaviorSettingsManager $behavior_settings_manager, TranslationInterface $translation) { $this->entityTypeManager = $etm; $this->allBundleInfo = $etbi->getAllBundleInfo(); - $this->rhBehaviorPluginManager = $behaviorPluginManager; - $this->rhEntityPluginManager = $entityPluginManager; - $this->rhBehaviorSettingsManager = $behaviorSettingsManager; + $this->rhBehaviorPluginManager = $behavior_plugin_manager; + $this->rhEntityPluginManager = $entity_plugin_manager; + $this->rhBehaviorSettingsManager = $behavior_settings_manager; $this->stringTranslation = $translation; } @@ -151,13 +151,13 @@ class FormManglerService { // TODO: Should be possible to get this as plural? Look into this. $entity_label = $entity_type->getLabel(); - $bundleInfo = isset($this->allBundleInfo[$entity_type->id()]) + $bundle_info = isset($this->allBundleInfo[$entity_type->id()]) ? $this->allBundleInfo[$entity_type->id()] : NULL; // Get the label for the bundle. This won't be set when the user is creating // a new bundle. In that case, fallback to "this bundle". - $bundle_label = NULL !== $bundleInfo && NULL !== $bundleInfo[$bundle]['label'] - ? $bundleInfo[$bundle]['label'] : $this->t('this bundle'); + $bundle_label = NULL !== $bundle_info && NULL !== $bundle_info[$bundle]['label'] + ? $bundle_info[$bundle]['label'] : $this->t('this bundle'); // Wrap everything in a fieldset. $form['rabbit_hole'] = array(