diff --git a/src/EntityExtender.php b/src/EntityExtender.php index c4c03b2..8a94eb8 100644 --- a/src/EntityExtender.php +++ b/src/EntityExtender.php @@ -44,10 +44,13 @@ class EntityExtender implements EntityExtenderInterface { } /** - * Return fields that rabbit hole adds for use in entity_base_field_info hooks. + * Return fields added by rabbit hole for use in entity_base_field_info hooks. * * @param string $entity_type_id - * The string ID of the entity type + * The string ID of the entity type. + * + * @return array + * An array of general extra fields. */ public function getRabbitHoleFields($entity_type_id) { $entity_types = $this->rhEntityPluginManager->loadSupportedEntityTypes(); diff --git a/src/EventSubscriber/RabbitHoleSubscriber.php b/src/EventSubscriber/RabbitHoleSubscriber.php index cc02138..c7d1d9c 100644 --- a/src/EventSubscriber/RabbitHoleSubscriber.php +++ b/src/EventSubscriber/RabbitHoleSubscriber.php @@ -35,7 +35,7 @@ class RabbitHoleSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} */ - static function getSubscribedEvents() { + static public function getSubscribedEvents() { $events['kernel.request'] = ['onRequest']; $events['kernel.response'] = ['onResponse']; return $events; diff --git a/src/Exception/InvalidBehaviorSettingException.php b/src/Exception/InvalidBehaviorSettingException.php index 9be3d60..1a4d447 100644 --- a/src/Exception/InvalidBehaviorSettingException.php +++ b/src/Exception/InvalidBehaviorSettingException.php @@ -1,26 +1,28 @@ setting = $setting; } /** - * + * TODO. */ public function getSetting() { return $this->setting(); diff --git a/src/Exception/InvalidRedirectResponseException.php b/src/Exception/InvalidRedirectResponseException.php index 985ed21..845a6d4 100644 --- a/src/Exception/InvalidRedirectResponseException.php +++ b/src/Exception/InvalidRedirectResponseException.php @@ -1,16 +1,18 @@ entityTypeManager->getStorage($entity_type) @@ -76,7 +77,7 @@ class FormManglerService { * * @param array $attach * The form that the Rabbit Hole form should be attached to. - * @param object $entity + * @param \Drupal\Core\Entity\Entity $entity * The entity that we're adding the form to, e.g. a node. This should be * defined even in the case of bundles since it is used to determine bundle * and entity type. @@ -92,7 +93,7 @@ class FormManglerService { * @param array $attach * The form that the Rabbit Hole form should be attached to. * @param string $entity_type_id - * The string ID of the entity type for the form, e.g. 'node' + * The string ID of the entity type for the form, e.g. 'node'. * @param object $entity * The entity that we're adding the form to, e.g. a node. This should be * defined even in the case of bundles since it is used to determine bundle @@ -147,16 +148,14 @@ class FormManglerService { // If the form is about to be attached to an entity, but the bundle isn't // allowed to be overridden, exit. // Get information about the entity. - /** - * @todo Should be possible to get this as plural? Look into this - */ + // TODO: Should be possible to get this as plural? Look into this. $entity_label = $entity_type->getLabel(); $bundleInfo = 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". + // 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'); @@ -166,20 +165,16 @@ class FormManglerService { '#title' => $this->t('Rabbit Hole settings'), '#collapsed' => FALSE, '#collapsible' => TRUE, - /** - * @todo Should probably handle group in a plugin - not sure if, e.g., - * files will work in the same way and even if they do later - * entities might not - */ + + // TODO: Should probably handle group in a plugin - not sure if, e.g., + // files will work in the same way and even if they do later entities + // might not. '#group' => $is_bundle_or_entity_type ? 'additional_settings' : 'advanced', '#attributes' => array('class' => array('rabbit-hole-settings-form')), ); // Add the invoking module to the internal values. - /** - * @todo This can probably be removed - check - */ - + // TODO: This can probably be removed - check. $form['rabbit_hole']['rh_is_bundle'] = array( '#type' => 'hidden', '#value' => $is_bundle_or_entity_type, @@ -205,8 +200,8 @@ class FormManglerService { $action_options = $this->loadBehaviorOptions(); if (!$is_bundle_or_entity_type) { - // Add an option if we are editing an entity. This will allow us to use the - // configuration for the bundle. + // Add an option if we are editing an entity. This will allow us to use + // the configuration for the bundle. $action_bundle = $bundle_settings->get('action'); $action_options = array( self::RABBIT_HOLE_USE_DEFAULT => t('Global @bundle behavior (@setting)', array('@bundle' => strtolower($bundle_label), '@setting' => $action_options[$action_bundle])), @@ -225,43 +220,41 @@ class FormManglerService { $this->populateExtraBehaviorSections($form, NULL, NULL, $entity, $is_bundle_or_entity_type, $bundle_settings); - /** - * @todo Add redirect settings - */ + // TODO: Add redirect settings. + // // Wrap the redirect settings in a fieldset. // Get the default value for the redirect path. - // Build the descriptive text. Add some help text for PHP, if the user has the - // permission to use PHP for evaluation. + // Build the descriptive text. Add some help text for PHP, if the user has + // the permission to use PHP for evaluation. // Add the redirect path setting. - /** - * @todo Add token support - */ + // + // TODO: Add token support. + // // Display a list of tokens if the Token module is enabled. - /** - * @todo Add specific options for redirect - possibly via the plugin? - */ - // Add the redirect respons setting. - /** - * @todo Handle possible PHP code in redirect - */ - // If the redirect path contains PHP, and the user doesn't have permission to - // use PHP for evaluation, we'll disable access to the path setting, and print - // some helpful information about what's going on. + // + // TODO: Add specific options for redirect - possibly via the plugin? + // + // Add the redirect response setting. + // + // TODO: Handle possible PHP code in redirect. + // + // If the redirect path contains PHP, and the user doesn't have permission + // to use PHP for evaluation, we'll disable access to the path setting, and + // print some helpful information about what's going on. + // // Attach the Rabbit Hole form to the main form, and add a custom validation // callback. $attach += $form; - /** - * @todo Optionally provide a form validation handler (can we do this via plugin?) - */ - - // If the implementing module provides a submit function for the bundle form, - // we'll add it as a submit function for the attached form. We'll also make - // sure that this won't be added for entity forms. - /** - * @todo This should probably be moved out into plugins based on entity type - */ - + // TODO: Optionally provide a form validation handler (can we do this via + // plugin?). + // + // If the implementing module provides a submit function for the bundle + // form, we'll add it as a submit function for the attached form. We'll also + // make sure that this won't be added for entity forms. + // + // TODO: This should probably be moved out into plugins based on entity + // type. $submit_handler_locations = $entity_plugin ->getFormSubmitHandlerAttachLocations(); @@ -273,17 +266,19 @@ class FormManglerService { $array_ref[] = '_rabbit_hole_general_form_submit'; } - /** - * @todo Optionally provide additional form submission handler (can we do this via plugin?) - */ + // TODO: Optionally provide additional form submission handler (can we do + // this via plugin?). } /** - * Handle general aspects of rabbit hole form submission (not specific to node - * etc.). + * Handle general aspects of rabbit hole form submission. + * + * (Not specific to node etc.). * * @param array $form - * @param string or int or object... &$form_state + * The form. + * @param string|int|object $form_state + * The form state. */ public function handleFormSubmit($form, $form_state) { if ($form_state->getValue('rh_is_bundle')) { @@ -311,10 +306,13 @@ class FormManglerService { } /** + * Load an array of behaviour options from plugins. + * * Load an array of rabbit hole behavior options from plugins in the format - * option id => label. + * option id => label. * - * @return array An array of behavior options + * @return array + * An array of behavior options */ protected function loadBehaviorOptions() { $action_options = array(); @@ -327,12 +325,18 @@ class FormManglerService { /** * Add additional fields to the form based on behaviors. * - * @param array &$form - * The form - * @param string or int or object... $form_state - * The form state - * @param string or int or object... $form_id - * The form ID + * @param array $form + * The form array. + * @param array $form_state + * The form state. + * @param string $form_id + * The form ID. + * @param \Drupal\Core\Entity\Entity|NULL $entity + * The entity whose settings form we are displaying. + * @param bool $entity_is_bundle + * Whether the entity is a bundle. + * @param \Drupal\Core\Config\ImmutableConfig|NULL $bundle_settings + * The settings for this bundle. */ protected function populateExtraBehaviorSections(&$form, $form_state, $form_id, Entity $entity = NULL, $entity_is_bundle = FALSE, @@ -347,7 +351,7 @@ class FormManglerService { } /** - * + * TODO. */ protected function isEntityBundle($entity) { return is_subclass_of($entity, diff --git a/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php b/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php index 849c189..57fd635 100644 --- a/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php +++ b/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php @@ -66,9 +66,7 @@ class PageRedirect extends RabbitHoleBehaviorPluginBase { // Return new RedirectResponse($this->path, $this->code);. $target = $entity->get('rh_redirect')->value; if (substr($target, 0, 4) == 'get('rh_redirect_response')->value) { @@ -154,8 +152,8 @@ class PageRedirect extends RabbitHoleBehaviorPluginBase { ); // Get the default value for the redirect path. - // Build the descriptive text. Add some help text for PHP, if the user has the - // permission to use PHP for evaluation. + // Build the descriptive text. Add some help text for PHP, if the user has + // the permission to use PHP for evaluation. $description = array(); $description[] = t('Enter the relative path or the full URL that the user should get redirected to. Query strings and fragments are supported, such as %example.', array('%example' => 'http://www.example.com/?query=value#fragment')); $description[] = t('You may enter tokens in this field.'); @@ -187,9 +185,9 @@ class PageRedirect extends RabbitHoleBehaviorPluginBase { '#attributes' => array('class' => array('rabbit-hole-redirect-response-setting')), ); - // If the redirect path contains PHP, and the user doesn't have permission to - // use PHP for evaluation, we'll disable access to the path setting, and print - // some helpful information about what's going on. + // If the redirect path contains PHP, and the user doesn't have permission + // to use PHP for evaluation, we'll disable access to the path setting, and + // print some helpful information about what's going on. } /** diff --git a/src/Plugin/RabbitHoleBehaviorPluginInterface.php b/src/Plugin/RabbitHoleBehaviorPluginInterface.php index c6cb5b3..5ed5444 100644 --- a/src/Plugin/RabbitHoleBehaviorPluginInterface.php +++ b/src/Plugin/RabbitHoleBehaviorPluginInterface.php @@ -23,11 +23,8 @@ interface RabbitHoleBehaviorPluginInterface extends PluginInspectionInterface { /** * Perform the rabbit hole action. * - * @param $entity - * The entity the action is being performed on - * @param $current_response - * The response as it currently exists before being replaced by the response - * returned by the rabbit hole plugin + * @param Entity $entity + * The entity the action is being performed on. */ public function performAction(Entity $entity); @@ -40,13 +37,13 @@ interface RabbitHoleBehaviorPluginInterface extends PluginInspectionInterface { * The form state array to modify. * @param string $form_id * The form ID. - * @param Entity $entity - * The entity used by the form + * @param Entity|null $entity + * The entity used by the form. * @param bool $entity_is_bundle - * Whether the entity is a bundle - * @param BehaviorSettings + * Whether the entity is a bundle. + * @param ImmutableConfig|null $bundle_settings * The behavior settings for the bundle of the entity (or the entity itself, - * if it is a bundle) + * if it is a bundle). */ public function settingsForm(&$form, &$form_state, $form_id, Entity $entity = NULL, $entity_is_bundle = FALSE, ImmutableConfig $bundle_settings = NULL); @@ -59,19 +56,20 @@ interface RabbitHoleBehaviorPluginInterface extends PluginInspectionInterface { /** * Add to or adjust the fields added by rabbit hole. * - * @param $fields The array of fields to be altered + * @param array $fields + * The array of fields to be altered. */ public function alterExtraFields(array &$fields); /** * Get whether this plugin uses a response to perform its action. * - * Override this to return one of USES_RESPONSE_NEVER, USES_RESPONSE_SOMETIMES, - * or USES_RESPONSE_ALWAYS to indicate whether performAction should be invoked - * only when a null response is given, regardless of whether there is - * a response (it'll figure out what to do with or without on its own), or - * only when a non-null response is given. Defaults to returning - * USES_RESPONSE_NEVER. + * Override this to return one of USES_RESPONSE_NEVER, + * USES_RESPONSE_SOMETIMES, or USES_RESPONSE_ALWAYS to indicate whether + * performAction() should be invoked only when a null response is given, + * regardless of whether there is a response (it'll figure out what to do with + * or without on its own), or only when a non-null response is given. Defaults + * to returning USES_RESPONSE_NEVER. */ public function usesResponse(); diff --git a/src/Plugin/RabbitHoleEntityPluginInterface.php b/src/Plugin/RabbitHoleEntityPluginInterface.php index ac23d6f..4a9d08a 100644 --- a/src/Plugin/RabbitHoleEntityPluginInterface.php +++ b/src/Plugin/RabbitHoleEntityPluginInterface.php @@ -15,41 +15,48 @@ use Drupal\Component\Plugin\PluginInspectionInterface; interface RabbitHoleEntityPluginInterface extends PluginInspectionInterface { /** - * Return locations to attach submit handlers to entities as an array of arrays, - * e.g.: + * Return locations to attach submit handlers to entities. + * + * This should return an array of arrays, e.g.: * array( - * array('actions', 'submit', '#publish'), - * array('actions', 'publish', '#submit'), + * array('actions', 'submit', '#publish'), + * array('actions', 'publish', '#submit'), * ). */ public function getFormSubmitHandlerAttachLocations(); /** - * Return locations to attach submit handlers to entity bundles as an array of - * arrays, e.g.: + * Return locations to attach submit handlers to entity bundles. + * + * This should return an array of arrays, e.g.: * array( - * array('actions', 'submit', '#publish'), - * array('actions', 'publish', '#submit'), + * array('actions', 'submit', '#publish'), + * array('actions', 'publish', '#submit'), * ). * - * @return array A multidimensional array + * @return array + * A multidimensional array. */ public function getBundleFormSubmitHandlerAttachLocations(); /** + * Return the form ID of the config form for this plugin's entity. + * * Return the form ID of the global config form for the entity targeted by * this plugin. * - * @return string The form ID of the global config form + * @return string + * The form ID of the global config form. */ public function getGlobalConfigFormId(); /** - * Return locations to attach submit handlers to the global config form as an - * array of arrays, e.g.: + * Return locations to attach submit handlers to the global config form. + * + * This should return an array of arrays, e.g.: * array( - * array('actions', 'submit', '#publish'), - * array('actions', 'publish', '#submit'), + * array('actions', 'submit', '#publish'), + * array('actions', 'publish', '#submit'), * ). */ public function getGlobalFormSubmitHandlerAttachLocations(); diff --git a/src/Plugin/RabbitHoleEntityPluginManager.php b/src/Plugin/RabbitHoleEntityPluginManager.php index 7514a0d..a2e4808 100644 --- a/src/Plugin/RabbitHoleEntityPluginManager.php +++ b/src/Plugin/RabbitHoleEntityPluginManager.php @@ -44,14 +44,16 @@ class RabbitHoleEntityPluginManager extends DefaultPluginManager { } /** + * Create an instance of the first plugin found with string id $entity_type. + * * Create an instance of the first plugin found supporting the entity type * with string id $entity_type. * * @param string $entity_type - * The string ID of the entity type + * The string ID of the entity type. * * @return Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginInterface - * The plugin + * The plugin. */ public function createInstanceByEntityType($entity_type) { $plugin_ids = array_keys($this->loadDefinitionsByEntityType($entity_type)); @@ -62,10 +64,10 @@ class RabbitHoleEntityPluginManager extends DefaultPluginManager { * Load plugins implementing entity with id $entity_type. * * @param string $entity_type - * The string ID of the entity type + * The string ID of the entity type. * * @return array - * An array of plugin definitions for the entity type with ID $entity_type + * An array of plugin definitions for the entity type with ID $entity_type. */ public function loadDefinitionsByEntityType($entity_type) { return array_filter($this->getDefinitions(), function($var) use ($entity_type) { @@ -77,7 +79,7 @@ class RabbitHoleEntityPluginManager extends DefaultPluginManager { * Load the string IDs for the supported entity types. * * @return array - * An array of entity type ID strings + * An array of entity type ID strings. */ public function loadSupportedEntityTypes() { return array_values(array_map(function($var) { @@ -89,7 +91,7 @@ class RabbitHoleEntityPluginManager extends DefaultPluginManager { * Load the string IDs for the supported bundle entity types. * * @return array - * An array of entity type ID strings + * An array of entity type ID strings. */ public function loadSupportedBundleEntityTypes() { return array_values(array_map(function($var, $this) { @@ -99,12 +101,11 @@ class RabbitHoleEntityPluginManager extends DefaultPluginManager { } /** - * Load the string IDs for the global configuration - * forms for entity types. + * Load the string IDs for the global configuration forms for entity types. * * @return array - * An array of entity types and form ID strings in the form - * form_id => entity_type + * An array of entity types and form ID strings in the form + * form_id => entity_type. */ public function loadSupportedGlobalForms() { $result = array(); diff --git a/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php b/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php index c1c7c06..0d3e418 100644 --- a/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php +++ b/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php @@ -14,6 +14,13 @@ use Drupal\rabbit_hole\Exception\InvalidBehaviorSettingException; * Test the functionality of the rabbit hole form additions to the node form. * * @group rabbit_hole + * + * TODO: Test that creating an entity with an invalid redirect code fails. + * TODO: Test that creating an entity with redirect settings when the action + * type is not redirect fails. + * + * Note: Currently config entity constructors don't use setters - see + * https://www.drupal.org/node/2399999. */ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { public static $modules = array('rabbit_hole'); @@ -62,21 +69,6 @@ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { } /** - * Test that creating an entity with an invalid redirect code fails. - * - * @note Currently config entity constructors don't use setters - see - * https://www.drupal.org/node/2399999 - */ - - /** - * Test that creating an entity with redirect settings when the action - * type is not redirect fails. - * - * @note Currently config entity constructors don't use setters - see - * https://www.drupal.org/node/2399999 - */ - - /** * Test that setAction() works as expected. */ public function testSetAction() { @@ -87,6 +79,8 @@ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { } /** + * Test that setAllowOverride works as expected. + * * Test that setAllowOverride works as expected (including throwing an * exception if an invalid value is passed). */ @@ -102,6 +96,8 @@ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { } /** + * Test that setRedirectCode works as expected. + * * Test that setRedirectCode works as expected (including throwing an * exception for invalid codes and settings codes when action type is wrong). */ @@ -127,6 +123,8 @@ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { } /** + * Test that setRedirectPath works as expected. + * * Test that setRedirectPath works as expected (including throwing an * exception for invalid codes and settings codes when action type is wrong). */ @@ -158,17 +156,19 @@ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { } /** + * Test that BehaviorSettingExceptions are thrown when we expect them to. + * * Test that a BehaviorSettingException gets thrown when $entity executes * $method with $args. This uses call_user_func internally. * * @param BehaviorSettings $entity - * The BehaviorSettings entity + * The BehaviorSettings entity. * @param string $method - * The method to call + * The method to call. * @param array $args - * The arguments to pass to the method + * The arguments to pass to the method. * @param string $parent - * The name of the method which calls this method + * The name of the method which calls this method. */ private function testBehaviorSettingExceptionThrown(BehaviorSettings $entity, $method, array $args, $parent) { $exception_was_thrown = FALSE; diff --git a/src/Tests/RabbitHoleBehaviorSettingsTest.php b/src/Tests/RabbitHoleBehaviorSettingsTest.php index cd4546a..b7b0e53 100644 --- a/src/Tests/RabbitHoleBehaviorSettingsTest.php +++ b/src/Tests/RabbitHoleBehaviorSettingsTest.php @@ -11,7 +11,7 @@ use Drupal\node\Entity\Node; use Drupal\rabbit_hole\Entity\BehaviorSettings; /** - * Test the functionality of the RabbitHoleBehaviorSettings configuration entity. + * Test the RabbitHoleBehaviorSettings configuration entity functionality. * * @group rabbit_hole */ @@ -52,6 +52,8 @@ class RabbitHoleBehaviorSettingsTest extends WebTestBase { } /** + * Test that a BehaviorSettings can be found and contains correct values. + * * Test that a saved BehaviorSettings entity can be found by the config system * and contains the correct values. */ @@ -75,6 +77,8 @@ class RabbitHoleBehaviorSettingsTest extends WebTestBase { } /** + * Test that a BehaviourSettings can be given an ID and found later. + * * Test that a saved BehaviourSettings entity can be given an ID based on * a generated bundle (a NodeType in this case) and be found based on that ID. */ @@ -87,8 +91,6 @@ class RabbitHoleBehaviorSettingsTest extends WebTestBase { /** * Test loading behavior settings for a nonexistent bundle returns defaults. - * - * @return type */ public function testLoadBundleSettingsWithDefault() { // We search for a bundle that doesn't exist (named from a UUID) expecting