diff -u b/captcha.inc b/captcha.inc --- b/captcha.inc +++ b/captcha.inc @@ -233,7 +233,7 @@ // By default however, probably all Drupal core forms // are already correctly handled with the best effort guess // based on the 'actions' element (see below). - $placement_map = module_invoke_all('captcha_placement_map'); + $placement_map = \Drupal::moduleHandler()->invokeAll('captcha_placement_map'); } } diff -u b/captcha.links.menu.yml b/captcha.links.menu.yml --- b/captcha.links.menu.yml +++ b/captcha.links.menu.yml @@ -13 +13 @@ - weight: 0 \ No newline at end of file + weight: 0 diff -u b/captcha.links.task.yml b/captcha.links.task.yml --- b/captcha.links.task.yml +++ b/captcha.links.task.yml @@ -11,4 +11,4 @@ -captcha_points_list: +captcha_points.list: route_name: captcha_point.list title: 'CAPTCHA Points' - base_route: captcha_settings \ No newline at end of file + base_route: captcha_settings diff -u b/captcha.module b/captcha.module --- b/captcha.module +++ b/captcha.module @@ -97,8 +97,8 @@ return array( 'captcha' => array( 'render element' => 'element', - // 'template' => 'captcha', - // 'path' => drupal_get_path('module', 'captcha') . '/templates', + 'template' => 'captcha', + 'path' => drupal_get_path('module', 'captcha') . '/templates', ), ); } @@ -221,13 +221,13 @@ if (_captcha_required_for_user($captcha_sid, $this_form_id) || $element['#captcha_admin_mode']) { // Generate a CAPTCHA and its solution // (note that the CAPTCHA session ID is given as third argument). - $captcha = module_invoke($captcha_type_module, 'captcha', 'generate', $captcha_type_challenge, $captcha_sid); + $captcha = \Drupal::moduleHandler()->invoke($captcha_type_module, 'captcha', array('generate', $captcha_type_challenge, $captcha_sid)); if (!isset($captcha['form']) || !isset($captcha['solution'])) { // The selected module did not return what we expected: log about it and quit. - watchdog('CAPTCHA', + \Drupal::logger('CAPTCHA')->error( 'CAPTCHA problem: unexpected result from hook_captcha() of module %module when trying to retrieve challenge type %type for form %form_id.', - array('%type' => $captcha_type_challenge, '%module' => $captcha_type_module, '%form_id' => $this_form_id), - WATCHDOG_ERROR); + array('%type' => $captcha_type_challenge, '%module' => $captcha_type_module, '%form_id' => $this_form_id) + ); return $element; } diff -u b/captcha.routing.yml b/captcha.routing.yml --- b/captcha.routing.yml +++ b/captcha.routing.yml @@ -36,6 +36,8 @@ defaults: _entity_form: 'captcha_point.edit' _title: 'Edit CAPTCHA point' + options: + _admin_route: TRUE requirements: _permission: 'administer CAPTCHA settings' @@ -47,2 +49,4 @@ + options: + _admin_route: TRUE requirements: - _permission: 'administer CAPTCHA settings' \ No newline at end of file + _permission: 'administer CAPTCHA settings' diff -u b/config/schema/captcha.schema.yml b/config/schema/captcha.schema.yml --- b/config/schema/captcha.schema.yml +++ b/config/schema/captcha.schema.yml @@ -5,8 +5,12 @@ - id: + formId: type: string - label: 'ID' + label: 'Form ID' + captchaType: + type: string + label: 'Captcha Type' label: type: label label: 'Label' uuid: - type: string \ No newline at end of file + type: string + label: 'UUID' \ No newline at end of file diff -u b/src/Controller/CaptchaPointListBuilder.php b/src/Controller/CaptchaPointListBuilder.php --- b/src/Controller/CaptchaPointListBuilder.php +++ b/src/Controller/CaptchaPointListBuilder.php @@ -7,10 +7,10 @@ namespace Drupal\captcha\Controller; -use Drupal\Core\Config\Entity\ConfigEntityListBuilder; -use Drupal\captcha\CaptchaPointInterface; +use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Entity\EntityInterface; -class CaptchaPointListBuilder extends ConfigEntityListBuilder { +class CaptchaPointListBuilder extends EntityListBuilder { /** * {@inheritdoc} */ @@ -27,8 +27,9 @@ */ - public function buildRow(CaptchaPointInterface $entity) { + public function buildRow(EntityInterface $entity) { $row['form_id'] = $entity->id(); $row['captcha_type'] = $entity->getCaptchaType(); return $row + parent::buildRow($entity); } + } diff -u b/src/Entity/CaptchaPoint.php b/src/Entity/CaptchaPoint.php --- b/src/Entity/CaptchaPoint.php +++ b/src/Entity/CaptchaPoint.php @@ -24,6 +24,7 @@ * "delete" = "Drupal\captcha\Form\CaptchaPointDeleteForm" * } * }, + * fieldable = FALSE, * config_prefix = "captcha_point", * admin_permission = "administer CAPTCHA settings", * entity_keys = { @@ -32,7 +33,7 @@ * }, * links = { * "edit-form" = "captcha_point.edit", - * "delete-form" = "captcha_point.delete" + * "delete-form" = "captcha_point.delete", * } * ) */ diff -u b/src/Form/CaptchaExamplesForm.php b/src/Form/CaptchaExamplesForm.php --- b/src/Form/CaptchaExamplesForm.php +++ b/src/Form/CaptchaExamplesForm.php @@ -51,7 +51,7 @@ module_load_include('inc', 'captcha', 'captcha.admin'); $module = $this->getRequest()->get('module'); - $challenge = $this->request->get('challenge'); + $challenge = $this->getRequest()->get('challenge'); $form = array(); if ($module && $challenge) { @@ -65,7 +65,7 @@ $form['info'] = array( '#markup' => t('This page gives an overview of all available challenge types, generated with their current settings.'), ); - foreach (module_implements('captcha') as $mkey => $module) { + foreach (\Drupal::moduleHandler()->getImplementations('captcha') as $mkey => $module) { $challenges = call_user_func_array($module . '_captcha', array('list')); if ($challenges) { diff -u b/src/Form/CaptchaPointDeleteForm.php b/src/Form/CaptchaPointDeleteForm.php --- b/src/Form/CaptchaPointDeleteForm.php +++ b/src/Form/CaptchaPointDeleteForm.php @@ -9,34 +9,46 @@ use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Builds the form to delete a Captcha Point. */ class CaptchaPointDeleteForm extends EntityConfirmFormBase { + /** * {@inheritdoc} */ public function getQuestion() { return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label())); } + /** * {@inheritdoc} */ public function getCancelRoute() { return new Url('captcha_point.list'); } + /** * {@inheritdoc} */ public function getConfirmText() { return $this->t('Delete'); } + /** * {@inheritdoc} */ public function submit(array $form, FormStateInterface $form_state) { $this->entity->delete(); - drupal_set_message($this->t('Category %label has been deleted.', array('%label' => $this->entity->label()))); + drupal_set_message($this->t('Captcha point %label has been deleted.', array('%label' => $this->entity->label()))); $form_state['redirect_route'] = $this->getCancelRoute(); } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + return new Url('captcha_point.list'); + } } diff -u b/src/Form/CaptchaPointForm.php b/src/Form/CaptchaPointForm.php --- b/src/Form/CaptchaPointForm.php +++ b/src/Form/CaptchaPointForm.php @@ -57,6 +57,7 @@ public function save(array $form, FormStateInterface $form_state) { $captcha_point = $this->entity; $status = $captcha_point->save(); + if ($status) { drupal_set_message($this->t('Captcha Point for %label form was saved.', array( '%label' => $captcha_point->label(), @@ -68,5 +69,5 @@ ))); } - $form_state['redirect'] = 'admin/config/people/captcha/captcha-points'; + $form_state->setRedirect('captcha_point.list'); } } diff -u b/src/Tests/CaptchaBaseWebTestCase.php b/src/Tests/CaptchaBaseWebTestCase.php --- b/src/Tests/CaptchaBaseWebTestCase.php +++ b/src/Tests/CaptchaBaseWebTestCase.php @@ -250,2 +250,15 @@ } + + /** + * Helper function to generate random names. + */ + protected function randomName($length = 8) { + $values = array_merge(range(65, 90), range(97, 122), range(48, 57)); + $max = count($values) - 1; + $str = chr(mt_rand(97, 122)); + for ($i = 1; $i < $length; $i++) { + $str .= chr($values[mt_rand(0, $max)]); + } + return $str; + } } diff -u b/src/Tests/CaptchaPersistenceTestCase.php b/src/Tests/CaptchaPersistenceTestCase.php --- b/src/Tests/CaptchaPersistenceTestCase.php +++ b/src/Tests/CaptchaPersistenceTestCase.php @@ -75,8 +75,7 @@ */ protected function assertDifferentCsid($captcha_sid_initial) { $captcha_sid = $this->getCaptchaSidFromForm(); - $this->assertNotEqual($captcha_sid_initial, $captcha_sid, - "CAPTCHA session ID should be different."); + $this->assertNotEqual($captcha_sid_initial, $captcha_sid, "CAPTCHA session ID should be different."); } /**