summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplopesc2013-06-04 18:34:04 (GMT)
committer Juampy2013-06-04 18:34:04 (GMT)
commit9956b39f67d0644a2c8ba0fe9b65ce2e8185cdf8 (patch)
tree5937dade78c58c418bc09045939191176fa14780
parent202d507ff3930b78f299ec3be5d59ec94689a6bf (diff)
Issue #2011876 by plopesc: Migrate settings page to Drupal 8.
-rw-r--r--lib/Drupal/twitter/Form/TwitterSettingsForm.php103
-rw-r--r--twitter.module5
-rw-r--r--twitter.routing.yml6
3 files changed, 110 insertions, 4 deletions
diff --git a/lib/Drupal/twitter/Form/TwitterSettingsForm.php b/lib/Drupal/twitter/Form/TwitterSettingsForm.php
new file mode 100644
index 0000000..1c25f89
--- /dev/null
+++ b/lib/Drupal/twitter/Form/TwitterSettingsForm.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\twitter\Form\TwitterSettingsForm.
+ */
+
+namespace Drupal\twitter\Form;
+
+use Drupal\system\SystemConfigFormBase;
+
+/**
+ * Configure twitter settings for this site.
+ */
+class TwitterSettingsForm extends SystemConfigFormBase {
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::getFormID().
+ */
+ public function getFormID() {
+ return 'twitter_settings_form';
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::buildForm().
+ */
+ public function buildForm(array $form, array &$form_state) {
+ $form['twitter_import'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Import and display the Twitter statuses of site users who have entered their Twitter account information.'),
+ '#default_value' => variable_get('twitter_import', 1),
+ );
+ $form['twitter_expire'] = array(
+ '#type' => 'select',
+ '#title' => t('Delete old statuses'),
+ '#default_value' => variable_get('twitter_expire', 0),
+ '#options' => array(0 => t('Never')) + drupal_map_assoc(array(604800, 2592000, 7776000, 31536000), 'format_interval'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name=twitter_import]' => array('checked' => TRUE),
+ ),
+ ),
+ );
+ $form['oauth'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('OAuth Settings'),
+ '#access' => module_exists('oauth_common'),
+ '#description' => t('To enable OAuth based access for twitter, you must <a href="@url">register your application</a> with Twitter and add the provided keys here.', array('@url' => 'https://dev.twitter.com/apps/new')),
+ );
+ $form['oauth']['callback_url'] = array(
+ '#type' => 'item',
+ '#title' => t('Callback URL'),
+ '#markup' => url('twitter/oauth', array('absolute' => TRUE)),
+ );
+ $form['oauth']['twitter_consumer_key'] = array(
+ '#type' => 'textfield',
+ '#title' => t('OAuth Consumer key'),
+ '#default_value' => variable_get('twitter_consumer_key', NULL),
+ );
+ $form['oauth']['twitter_consumer_secret'] = array(
+ '#type' => 'textfield',
+ '#title' => t('OAuth Consumer secret'),
+ '#default_value' => variable_get('twitter_consumer_secret', NULL),
+ );
+ // Twitter external APIs settings.
+ $form['twitter'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Twitter Settings'),
+ '#description' => t('The following settings connect Twitter module with external APIs. ' .
+ 'Change them if, for example, you want to use Identi.ca.'),
+ );
+ $form['twitter']['twitter_host'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Twitter host'),
+ '#default_value' => variable_get('twitter_host', TWITTER_HOST),
+ );
+ $form['twitter']['twitter_api'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Twitter API'),
+ '#default_value' => variable_get('twitter_api', TWITTER_API),
+ );
+ $form['twitter']['twitter_search'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Twitter search'),
+ '#default_value' => variable_get('twitter_search', TWITTER_SEARCH),
+ );
+ $form['twitter']['twitter_tinyurl'] = array(
+ '#type' => 'textfield',
+ '#title' => t('TinyURL'),
+ '#default_value' => variable_get('twitter_tinyurl', TWITTER_TINYURL),
+ );
+
+ return parent::buildForm($form, $form_state);
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::submitForm().
+ */
+ public function submitForm(array &$form, array &$form_state) {
+
+ parent::submitForm($form, $form_state);
+ }
+
+}
diff --git a/twitter.module b/twitter.module
index 894930d..b4eae4d 100644
--- a/twitter.module
+++ b/twitter.module
@@ -70,10 +70,7 @@ function twitter_menu() {
$items['admin/config/services/twitter/settings'] = array(
'title' => 'Settings',
'description' => 'Twitter settings.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('twitter_admin_form'),
- 'access arguments' => array('administer site configuration'),
- 'file' => 'twitter.pages.inc',
+ 'route_name' => 'twitter_settings_form',
'type' => MENU_LOCAL_TASK,
);
diff --git a/twitter.routing.yml b/twitter.routing.yml
new file mode 100644
index 0000000..24445d6
--- /dev/null
+++ b/twitter.routing.yml
@@ -0,0 +1,6 @@
+twitter_settings_form:
+ pattern: '/admin/config/services/twitter/settings'
+ defaults:
+ _form: '\Drupal\twitter\Form\TwitterSettingsForm'
+ requirements:
+ _permission: 'administer site configuration'