page_tester-1.0.x-dev/page_tester.module
page_tester.module
<?php
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Implements hook_help().
*/
function page_tester_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.page_tester':
$output = '';
$output .= '<h2>' . t('About') . '</h2>';
$output .= '<p>' . t('This project allows the developer to walk through complicated testing scenarios. It puts a block with a form on the page and allows the admin to walk through pages to make sure they work well.') . '</p>';
$output .= '<h2>' . t('Uses') . '</h2>';
$output .= '<dl>';
$output .= '<dt>' . t('Using page tester') . '</dt>';
$output .= '<dd>' . t('<em>Simple actions</em> do not require configuration and are listed automatically as available on the.') . '</dd>';
$output .= '<dt>' . t('Creating and configuring advanced actions') . '</dt>';
$output .= '<dd>' . t('<em>Advanced actions</em> are user-created and have to be configured individually. Create an advanced action on the.') . '</dd>';
$output .= '</dl>';
return $output;
}
}
/**
* Implements hook_entity_operation_alter().
*/
function page_tester_entity_operation_alter(array &$operations, EntityInterface $entity) {
if ($entity->getEntityTypeId() === 'page_tester_test') {
$block_storage = \Drupal::entityTypeManager()->getStorage('block');
$blocks = $block_storage->loadByProperties(['plugin' => 'page_tester_block']);
foreach ($blocks as $block) {
/** @var \Drupal\block\Entity\Block $block */
$plugin = $block->getPlugin();
$configuration = $plugin->getConfiguration();
if($configuration['page_tester_block_test_type'] == $entity->id()) {
$tests = \Drupal::service('page_tester.pagetester_service')->getTestPlugin($entity->id());
$firstTest = \Drupal::service('page_tester.pagetester_service')->getFirstIndex($tests->getTests($entity->id()));
$sessionName = 'page_tests_array_'. $entity->id();
$page_tests_array = \Drupal::request()->getSession()->get($sessionName, []);
$page_tests_array['test'] = $firstTest;
\Drupal::request()->getSession()->set($sessionName, $page_tests_array);
$visibility = $block->getVisibility();
if (isset($visibility['request_path']['pages'])) {
$pages = explode("\r\n", $visibility['request_path']['pages']);
if(isset($pages[0])) {
$operations['start_testing'] = [
'title' => t('Start Testing'),
'url' => Url::fromUri('internal:'. $pages[0]),
'weight' => 50,
];
}
}
}
}
}
}
