diff --git a/modules/rh_node/rh_node.module b/modules/rh_node/rh_node.module index 5c3fce3..bcddddb 100644 --- a/modules/rh_node/rh_node.module +++ b/modules/rh_node/rh_node.module @@ -9,8 +9,6 @@ function rh_node_form_node_type_form_alter(&$form, $form_state) { // Add the Rabbit Hole form, and add an extra javascript file that's needed // for the fieldset summary. - // \Drupal::service('rabbit_hole.form_mangler')->addRabbitHoleOptionsToEntityForm( - // $form, 'rh_node', $form_state->getFormObject()->getEntity()); $form['#attached']['library'][] = 'rh_node/node-form'; } @@ -23,21 +21,9 @@ function rh_node_form_node_type_form_alter(&$form, $form_state) { function rh_node_form_node_form_alter(&$form, $form_state) { // Add the Rabbit Hole form, and add an extra javascript file that's needed // for the fieldset summary. - // \Drupal::service('rabbit_hole.form_mangler')->addRabbitHoleOptionsToEntityForm( - // $form, 'rh_node', $form_state->getFormObject()->getEntity()); - // $form['#attached']['library'][] = 'rh_node/node-form'; - - // $form_state->setSubmitHandlers( - // array_merge($form_state->getSubmitHandlers(), - // array('_rabbit_hole_general_form_submit')) - // ); - // Add a custom submit function. This is used to disable the redirect to // node/123 if Rabbit Hole is enabled and the user doesn't have the bypass // rh_node permission. - // if (!user_access('bypass rh_node')) { - // $form['actions']['submit']['#submit'][] = 'rh_node_node_form_submit'; - // } } function rh_node_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) { diff --git a/modules/rh_node/src/Tests/InvocationTest.php b/modules/rh_node/src/Tests/InvocationTest.php index 1a20b23..de5193c 100644 --- a/modules/rh_node/src/Tests/InvocationTest.php +++ b/modules/rh_node/src/Tests/InvocationTest.php @@ -166,7 +166,6 @@ class InvocationTest extends WebTestBase { $node->set('rh_redirect_response', $redirect_code); $node->save(); $this->drupalGet(self::NODE_BASE_PATH . $node->id()); - // $this->assertResponse($redirect_code); $this->assertUrl($base_root . $destination_path); } } diff --git a/modules/rh_user/rh_user.module b/modules/rh_user/rh_user.module index b32bab9..1a34dae 100644 --- a/modules/rh_user/rh_user.module +++ b/modules/rh_user/rh_user.module @@ -1,68 +1,6 @@ addRabbitHoleOptionsToEntityForm( -// $form, 'rh_user', $form_state->getFormObject()->getEntity()); -// } - -// function rh_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { -// switch ($form_id) { - // case 'user_form': - // case 'user_register_form': - // \Drupal::service('rabbit_hole.form_mangler')->addRabbitHoleOptionsToEntityForm( - // $form, 'rh_user', $form_state->getFormObject()->getEntity()); - // break; - // case 'user_admin_settings': - // break; -// } -//} - function rh_user_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) { return \Drupal::service('rabbit_hole.entity_extender') ->getRabbitHoleFields('user'); } - -/** - * Implements hook_form_FORM_ID_alter(). - * - * This will add Rabbit Hole options to the user form. These settings will - * be used as default for every node of this node type. - */ -// function rh_user_form_user_profile_form_alter(&$form, $form_state) { -// // Add the Rabbit Hole form, and add an extra javascript file that's needed -// // for the fieldset summary. -// \Drupal::service('rabbit_hole.form_mangler')->addRabbitHoleOptionsToEntityForm( -// $form, 'rh_user', $form_state->getFormObject()->getEntity()); -// } - -/** - * Implements hook_form_FORM_ID_alter(). - * - * This will add Rabbit Hole options to the node form. The user will be able to - * override the default Rabbit Hole options. - */ -// function rh_user_form_user_register_form_alter(&$form, $form_state) { - // Add the Rabbit Hole form, and add an extra javascript file that's needed - // for the fieldset summary. - // \Drupal::service('rabbit_hole.form_mangler')->addRabbitHoleOptionsToEntityForm( - // $form, 'rh_node', $form_state->getFormObject()->getEntity()); - - // $form_state->setSubmitHandlers( - // array_merge($form_state->getSubmitHandlers(), - // array('_rabbit_hole_general_form_submit')) - // ); - - // Add a custom submit function. This is used to disable the redirect to - // node/123 if Rabbit Hole is enabled and the user doesn't have the bypass - // rh_node permission. - // if (!user_access('bypass rh_node')) { - // $form['actions']['submit']['#submit'][] = 'rh_node_node_form_submit'; - // } -// } diff --git a/src/FormManglerService.php b/src/FormManglerService.php index 45a5409..3e4f336 100644 --- a/src/FormManglerService.php +++ b/src/FormManglerService.php @@ -152,25 +152,13 @@ class FormManglerService { $entity_plugin = $this->rhEntityPluginManager->createInstanceByEntityType( $entity_type_id); - // if (!user_access('administer ' . $module)) { - // The user doesn't have access, exit. - // return; - // } + // If the user doesn't have access, exit. - // if (isset($entity) && !rabbit_hole_get_override_bundle($entity_type, $bundle)) { - // // The form is about to be attached to an entity, but the bundle isn't - // // allowed to be overridden. Exit. - // return; - // } + // If the form is about to be attached to an entity, but the bundle isn't + // allowed to be overridden, exit. - // if (isset($entity) - // && !$this->getOverrideBundle($entity_type->getLabel(), $bundle)) { - // return; - // } // Get information about the entity. - // $entity_info = entity_get_info($entity_type); - // $entity_label = strtolower(isset($entity_info['plural label']) ? $entity_info['plural label'] : $entity_info['label']); /** * @todo Should be possible to get this as plural? Look into this */ @@ -181,7 +169,6 @@ class FormManglerService { // 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 = isset($entity_info['bundles'][$bundle]['label']) ? $entity_info['bundles'][$bundle]['label'] : 'this bundle'; $bundle_label = NULL !== $bundleInfo && NULL !== $bundleInfo[$bundle]['label'] ? $bundleInfo[$bundle]['label'] : $this->t('this bundle'); @@ -199,16 +186,11 @@ class FormManglerService { '#group' => $is_bundle_or_entity_type ? 'additional_settings' : 'advanced', '#attributes' => array('class' => array('rabbit-hole-settings-form')), ); - // $form['path']['#group'] = 'rabbit_hole'; // Add the invoking module to the internal values. /** * @todo This can probably be removed - check */ -// $form['rabbit_hole']['rh_module'] = array( -// '#type' => 'value', -// '#value' => $module, -// ); $form['rabbit_hole']['rh_is_bundle'] = array( '#type' => 'hidden', @@ -259,83 +241,23 @@ class FormManglerService { * @todo Add redirect settings */ // Wrap the redirect settings in a fieldset. - // $form['rabbit_hole']['redirect'] = array( - // '#type' => 'fieldset', - // '#title' => t('Redirect settings'), - // '#attributes' => array('class' => array('rabbit-hole-redirect-options')), - // '#states' => array( - // 'visible' => array( - // ':input[name="' . $action_setting_name . '"]' => array('value' => '3'), - // ), - // ), - // ); // Get the default value for the redirect path. - // $redirect_default_value = isset($entity) ? rabbit_hole_get_redirect_entity($entity_type, $entity) : (!empty($bundle) ? rabbit_hole_get_redirect_bundle($entity_type, $bundle) : RABBIT_HOLE_PAGE_REDIRECT_DEFAULT); // Build the descriptive text. Add some help text for PHP, if the user has the // permission to use PHP for evaluation. - // $description = array(); - // $description[] = $this->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')); - // if (rabbit_hole_access_php($module)) { - // $placeholders = array( - // '!surround' => '<?php and ?>', - // '!abort' => 'FALSE', - // '!variable' => '$entity', - // ); - // $description[] = t("You are able to evaluate PHP to determine the redirect. Surround your code by !surround. The returned string will replace the PHP part. However, you are able to return !abort if the user shouldn't get redirected. The !variable variable is available for use.", $placeholders); - // } - // $description[] = $this->t('You may enter tokens in this field.'); // Add the redirect path setting. - // $redirect_setting_name = isset($entity) ? 'rh_redirect' : 'rh_' . $entity_type->id() . '_redirect'; - // $form['rabbit_hole']['redirect']['redirect_setting_name'] = array( - // '#type' => 'value', - // '#value' => $redirect_setting_name, - // ); - // $form['rabbit_hole']['redirect'][$redirect_setting_name] = array( - // // '#type' => rabbit_hole_access_php($module) ? 'textarea' : 'textfield', - // '#type' => 'textfield', - // '#title' => t('Redirect path'), - // // '#default_value' => $redirect_default_value, - // '#description' => '

' . implode('

', $description) . '

', - // '#attributes' => array('class' => array('rabbit-hole-redirect-setting')), - // // '#rows' => substr_count($redirect_default_value, "\r\n") + 2, - // ); /** * @todo Add token support */ // Display a list of tokens if the Token module is enabled. - // if (module_exists('token')) { - // $entity_info = entity_get_info($entity_type); - // $form['rabbit_hole']['redirect']['token_info'] = array( - // '#theme' => 'token_tree', - // '#token_types' => array($entity_info['token type']), - // '#dialog' => TRUE, - // ); - // } /** * @todo Add specific options for redirect - possibly via the plugin? */ // Add the redirect respons setting. - // $redirect_response_setting_name = isset($entity) ? 'rh_redirect_response' : 'rh_' . $entity_type . '_redirect_response'; - // $form['rabbit_hole']['redirect'][$redirect_response_setting_name] = array( - // '#type' => 'select', - // '#title' => t('Response code'), - // '#options' => array( - // 301 => $this->t('301 (Moved Permanently)'), - // 302 => $this->t('302 (Found)'), - // 303 => $this->t('303 (See other)'), - // 304 => $this->t('304 (Not modified)'), - // 305 => $this->t('305 (Use proxy)'), - // 307 => $this->t('307 (Temporary redirect)'), - // ), - // // '#default_value' => isset($entity) ? rabbit_hole_get_redirect_response_entity($entity_type, $entity) : (!empty($bundle) ? rabbit_hole_get_redirect_response_bundle($entity_type, $bundle) : RABBIT_HOLE_PAGE_REDIRECT_RESPONSE_DEFAULT), - // '#description' => $this->t('The response code that should be sent to the users browser. Follow !link for more information on response codes.', array('!link' => l(t('this link'), 'http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_goto/7'))), - // '#attributes' => array('class' => array('rabbit-hole-redirect-response-setting')), - // ); /** * @todo Handle possible PHP code in redirect @@ -343,13 +265,6 @@ class FormManglerService { // 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 (rabbit_hole_contains_php($redirect_default_value) && !rabbit_hole_access_php($module)) { - // $form['rabbit_hole']['redirect']['#description'] = t("You're not able to edit the redirect path since it contain's PHP, and you're not allowed to evaluate PHP for this redirect."); - // $form['rabbit_hole']['redirect'][$redirect_setting_name]['#access'] = FALSE; - // if (isset($form['rabbit_hole']['redirect']['token_info'])) { - // $form['rabbit_hole']['redirect']['token_info']['#access'] = FALSE; - // } - // } // Attach the Rabbit Hole form to the main form, and add a custom validation // callback. $attach += $form; @@ -357,7 +272,6 @@ class FormManglerService { /** * @todo Optionally provide a form validation handler (can we do this via plugin?) */ - // $attach['#validate'][] = 'rabbit_hole_form_validate'; // 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 @@ -366,8 +280,6 @@ class FormManglerService { /** * @todo This should probably be moved out into plugins based on entity type */ - // $attach['actions']['submit']['#submit'][] = '_rabbit_hole_general_form_submit'; - // $attach['actions']['publish']['#submit'][] = '_rabbit_hole_general_form_submit'; $submit_handler_locations = $entity_plugin ->getFormSubmitHandlerAttachLocations(); @@ -383,10 +295,6 @@ class FormManglerService { /** * @todo Optionally provide additional form submission handler (can we do this via plugin?) */ - // $submit_function = $module . '_bundle_form_submit'; - // if (function_exists($submit_function) && !isset($entity)) { - // $attach['#submit'][] = $submit_function; - // } } /** diff --git a/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php b/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php index 3de1af6..01c18a8 100644 --- a/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php +++ b/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php @@ -156,20 +156,11 @@ class PageRedirect extends RabbitHoleBehaviorPluginBase { ); // Get the default value for the redirect path. - // $redirect_default_value = isset($entity) ? rabbit_hole_get_redirect_entity($entity_type, $entity) : (!empty($bundle) ? rabbit_hole_get_redirect_bundle($entity_type, $bundle) : RABBIT_HOLE_PAGE_REDIRECT_DEFAULT); // 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')); - // if (rabbit_hole_access_php($module)) { - // $placeholders = array( - // '!surround' => '<?php and ?>', - // '!abort' => 'FALSE', - // '!variable' => '$entity', - // ); - // $description[] = t("You are able to evaluate PHP to determine the redirect. Surround your code by !surround. The returned string will replace the PHP part. However, you are able to return !abort if the user shouldn't get redirected. The !variable variable is available for use.", $placeholders); - // } $description[] = t('You may enter tokens in this field.'); $form['rabbit_hole']['redirect']['rh_redirect'] = array( @@ -181,14 +172,6 @@ class PageRedirect extends RabbitHoleBehaviorPluginBase { '#rows' => substr_count($redirect_path, "\r\n") + 2, ); // Display a list of tokens if the Token module is enabled. - // if (module_exists('token')) { - // $entity_info = entity_get_info($entity_type); - // $form['rabbit_hole']['redirect']['token_info'] = array( - // '#theme' => 'token_tree', - // '#token_types' => array($entity_info['token type']), - // '#dialog' => TRUE, - // ); - // } // Add the redirect response setting. $form['rabbit_hole']['redirect']['rh_redirect_response'] = array( @@ -211,13 +194,6 @@ class PageRedirect extends RabbitHoleBehaviorPluginBase { // 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 (rabbit_hole_contains_php($redirect_default_value) && !rabbit_hole_access_php($module)) { - // $form['rabbit_hole']['redirect']['#description'] = t("You're not able to edit the redirect path since it contain's PHP, and you're not allowed to evaluate PHP for this redirect."); - // $form['rabbit_hole']['redirect'][$redirect_setting_name]['#access'] = FALSE; - // if (isset($form['rabbit_hole']['redirect']['token_info'])) { - // $form['rabbit_hole']['redirect']['token_info']['#access'] = FALSE; - // } - // } } /** diff --git a/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php b/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php index 9a43f19..b67097d 100644 --- a/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php +++ b/src/Tests/RabbitHoleBehaviorSettingsEntityMethodsTest.php @@ -68,25 +68,6 @@ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { * @note Currently config entity constructors don't use setters - see * https://www.drupal.org/node/2399999 */ - // public function testCreateEntityInvalidRedirectCode() { - // $action = 'redirect'; - // $redirect_code = 16709278; - // $redirect_path = '/'; - // $exception_was_thrown = FALSE; - // try { - // $entity = BehaviorSettings::create( - // array( - // 'id' => 'test_behavior_settings', - // 'action' => $action, - // 'redirect_code' => $redirect_code, - // 'redirect_path' => $redirect_path, - // ) - // ); - // } catch (InvalidBehaviorSettingException $ex) { - // $exception_was_thrown = TRUE; - // } - // $this->assertTrue($exception_was_thrown); - // } /** * Test that creating an entity with redirect settings when the action @@ -94,43 +75,6 @@ class RabbitHoleBehaviorSettingsEntityMethodsTest extends WebTestBase { * @note Currently config entity constructors don't use setters - see * https://www.drupal.org/node/2399999 */ - // public function testCreateEntityRedirectSettingsForWrongAction() { - // $action = 'display_page'; - // $redirect_code_none = BehaviorSettings::REDIRECT_NOT_APPLICABLE; - // $redirect_path_none = ''; - // $redirect_code = BehaviorSettings::REDIRECT_FOUND; - // $redirect_path = '/'; - - // $exception_was_thrown = FALSE; - // try { - // $entity = BehaviorSettings::create( - // array( - // 'id' => 'test_behavior_settings', - // 'action' => $action, - // 'redirect_code' => $redirect_code, - // 'redirect_path' => $redirect_path_none, - // ) - // ); - // } catch (InvalidBehaviorSettingException $ex) { - // $exception_was_thrown = TRUE; - // } - // $this->assertTrue($exception_was_thrown); - - // $exception_was_thrown = FALSE; - // try { - // $entity = BehaviorSettings::create( - // array( - // 'id' => 'test_behavior_settings_2', - // 'action' => $action, - // 'redirect_code' => $redirect_code_none, - // 'redirect_path' => $redirect_path, - // ) - // ); - // } catch (InvalidBehaviorSettingException $ex) { - // $exception_was_thrown = TRUE; - // } - // $this->assertTrue($exception_was_thrown); - // } /** * Test that setAction() works as expected diff --git a/src/Tests/RabbitHoleBehaviorSettingsTest.php b/src/Tests/RabbitHoleBehaviorSettingsTest.php index 22d05d8..be93b1e 100644 --- a/src/Tests/RabbitHoleBehaviorSettingsTest.php +++ b/src/Tests/RabbitHoleBehaviorSettingsTest.php @@ -192,9 +192,4 @@ class RabbitHoleBehaviorSettingsTest extends WebTestBase { $this->testNode->delete(); } - // TODO - // public function testSaveBundleSettingsViaForm() {} - - // TODO - // public function testSaveEntitySettingsViaForm() {} }