public function ShrinkTheWebSettingsForm::buildForm in ShrinkTheWeb 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ ShrinkTheWebSettingsForm.php, line 21
Class
Namespace
Drupal\shrinktheweb\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('shrinktheweb.settings');
module_load_include('inc', 'shrinktheweb', 'shrinktheweb.api');
$aAccountInfo = shrinktheweb_getAccountInfo();
$response_status = $aAccountInfo['stw_response_status'];
$inside_pages = !is_null($aAccountInfo['stw_inside_pages']) ? $aAccountInfo['stw_inside_pages']
->__toString() : 0;
$custom_size = $aAccountInfo['stw_custom_size'];
$full_length = !is_null($aAccountInfo['stw_full_length']) ? $aAccountInfo['stw_full_length']
->__toString() : 0;
$custom_delay = $aAccountInfo['stw_custom_delay'];
$custom_quality = $aAccountInfo['stw_custom_quality'];
$custom_resolution = $aAccountInfo['stw_custom_resolution'];
$custom_messages = $aAccountInfo['stw_custom_messages'];
if ($config
->get('shrinktheweb_token') == '') {
$generator = new Random();
$config
->set('shrinktheweb_token', $generator
->name(32, TRUE));
$config
->save();
}
$form = array();
$form['shrinktheweb_clearcache'] = array(
'#type' => 'fieldset',
'#title' => t('ShrinkTheWeb Clear Cache'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['shrinktheweb_clearcache']['shrinktheweb_clear_imagecache'] = array(
'#type' => 'checkbox',
'#title' => t('Clear Cached Screenshots'),
'#default_value' => FALSE,
'#description' => t('By selecting this checkbox all cached thumbshots gets deleted'),
'#disabled' => FALSE,
);
$form['shrinktheweb_clearcache']['shrinktheweb_clear_errorcache'] = array(
'#type' => 'checkbox',
'#title' => t('Clear Error Images'),
'#default_value' => FALSE,
'#description' => t('By selecting this checkbox all cached error images gets deleted'),
'#disabled' => FALSE,
);
$form['shrinktheweb_clearcache']['shrinktheweb_refresh_thumbnails'] = array(
'#type' => 'checkbox',
'#title' => t('Refresh All Thumbnails'),
'#default_value' => FALSE,
'#description' => t('By selecting this checkbox, all sites with cached thumbnails will be re-captured and the latest screenshots downloaded automatically'),
'#disabled' => FALSE,
);
$form['shrinktheweb_info'] = array(
'#type' => 'fieldset',
'#title' => t('ShrinkTheWeb Information'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['shrinktheweb_info']['shrinktheweb_get_account'] = array(
'#type' => 'item',
'#title' => t('Get Account'),
'#description' => t('You can get your "Access Key" and "Secret Key" by signing up for automated screenshots at: <a target="_blank" href="https://shrinktheweb.com/">ShrinkTheWeb</a>'),
);
$form['shrinktheweb_info']['shrinktheweb_referrer_list'] = array(
'#type' => 'item',
'#title' => t('Referrer List'),
'#description' => t('By default, you must add your server\'s IP address to <a href="https://shrinktheweb.com/content/how-do-i-lock-my-account.html" target="_blank">ShrinkTheWeb\'s "Allowed Referrers" list</a>'),
);
$form['shrinktheweb_info']['shrinktheweb_usage_instructions'] = array(
'#type' => 'item',
'#title' => t('Usage Instructions'),
'#description' => t('This module adds new field formatters to the fields of type Link. You can also put screenshots anywhere in PHP code. This module works with <a href="https://www.drupal.org/project/views_php" target="_blank">Views PHP</a> or <a href="https://www.drupal.org/project/php" target="_blank">PHP</a> module. <a href="https://www.drupal.org/node/1067900" target="_blank">Learn more</a>'),
);
$form['shrinktheweb_keys'] = array(
'#type' => 'fieldset',
'#title' => t('ShrinkTheWeb API keys'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['shrinktheweb_keys']['shrinktheweb_access_key'] = array(
'#type' => 'textfield',
'#title' => t('Access key'),
'#default_value' => $config
->get('shrinktheweb_access_key'),
'#required' => TRUE,
);
$form['shrinktheweb_keys']['shrinktheweb_secret_key'] = array(
'#type' => 'textfield',
'#title' => t('Secret key'),
'#default_value' => $config
->get('shrinktheweb_secret_key'),
'#required' => TRUE,
);
if ($config
->get('shrinktheweb_access_key') == '' || $config
->get('shrinktheweb_secret_key') == '' || $response_status != 'Success') {
$form['shrinktheweb_keys']['shrinktheweb_status'] = array(
'#type' => 'item',
'#title' => t('Invalid account credentials detected'),
'#description' => t('Please enter your account credentials and make sure they are correct'),
);
}
else {
$form['shrinktheweb_options'] = array(
'#type' => 'fieldset',
'#title' => t('ShrinkTheWeb Options'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['shrinktheweb_options']['shrinktheweb_notifynopush'] = array(
'#type' => 'select',
'#title' => t('Screenshot Delivery Method'),
'#options' => array(
0 => t('Recieve data with notification'),
1 => t('Make separate request for data'),
),
'#default_value' => $config
->get('shrinktheweb_notifynopush'),
'#required' => TRUE,
'#description' => t('Making a separate request for data uses more server resources but will reduce bandwidth usage when working with large images or large quantities of images'),
);
if ($config
->get('shrinktheweb_enable_https_set_automatically') == 0) {
$form['shrinktheweb_options']['shrinktheweb_enable_https'] = array(
'#type' => 'select',
'#title' => t('Enable HTTP Secure (HTTPS)'),
'#options' => array(
0 => t('Disable'),
1 => t('Enable'),
),
'#default_value' => $config
->get('shrinktheweb_enable_https'),
'#required' => TRUE,
);
}
$form['shrinktheweb_options']['shrinktheweb_token'] = array(
'#type' => 'textfield',
'#title' => t('Token'),
'#default_value' => $config
->get('shrinktheweb_token'),
'#description' => t('Random token for getting screenshots'),
'#size' => 32,
'#maxlength' => 32,
);
$form['shrinktheweb_options']['shrinktheweb_inside_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Inside Page Captures'),
'#default_value' => $inside_pages == 1 ? TRUE : FALSE,
'#description' => $inside_pages == 0 ? t('Upgrade required to use this feature') : t('i.e. not just homepages and sub-domains, auto selected since you have purchased this pro feature'),
'#disabled' => TRUE,
);
$form['shrinktheweb_options']['shrinktheweb_thumb_size'] = array(
'#type' => 'select',
'#title' => t('Default Thumbnail size'),
'#options' => array(
'mcr' => t('mcr'),
'tny' => t('tny'),
'vsm' => t('vsm'),
'sm' => t('sm'),
'lg' => t('lg'),
'xlg' => t('xlg'),
),
'#default_value' => $config
->get('shrinktheweb_thumb_size'),
'#required' => TRUE,
'#description' => t('width: mcr 75px, tny 90px, vsm 100px, sm 120px, lg 200px, xlg 320px'),
);
$form['shrinktheweb_options']['shrinktheweb_thumb_size_custom'] = array(
'#type' => 'textfield',
'#title' => t('Custom Width'),
'#default_value' => $custom_size == 0 && $full_length == 0 ? '' : $config
->get('shrinktheweb_thumb_size_custom'),
'#description' => $custom_size == 0 && $full_length == 0 ? t('Upgrade required to use this feature') : t('Enter your custom image width, this will override default size'),
'#size' => 10,
'#maxlength' => 10,
'#disabled' => $custom_size == 1 || $full_length == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_options']['shrinktheweb_full_size'] = array(
'#type' => 'checkbox',
'#title' => t('Full-Length capture'),
'#default_value' => $full_length == 0 ? FALSE : $config
->get('shrinktheweb_full_size'),
'#description' => $full_length == 0 ? t('Upgrade required to use this feature') : '',
'#disabled' => $full_length == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_options']['shrinktheweb_max_height'] = array(
'#type' => 'textfield',
'#title' => t('Max height'),
'#default_value' => $full_length == 0 ? '' : $config
->get('shrinktheweb_max_height'),
'#description' => $full_length == 0 ? t('Upgrade required to use this feature') : t('use if you want to set maxheight for fullsize capture'),
'#size' => 10,
'#maxlength' => 10,
'#disabled' => $full_length == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_options']['shrinktheweb_native_res'] = array(
'#type' => 'textfield',
'#title' => t('Native resolution'),
'#default_value' => $custom_resolution == 0 ? '' : $config
->get('shrinktheweb_native_res'),
'#description' => $custom_resolution == 0 ? t('Upgrade required to use this feature') : t('i.e. 640 for 640x480'),
'#size' => 10,
'#maxlength' => 10,
'#disabled' => $custom_resolution == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_options']['shrinktheweb_widescreen_y'] = array(
'#type' => 'textfield',
'#title' => t('Widescreen resolution Y'),
'#default_value' => $custom_resolution == 0 ? '' : $config
->get('shrinktheweb_widescreen_y'),
'#description' => $custom_resolution == 0 ? t('Upgrade required to use this feature') : t('i.e. 900 for 1440x900 if 1440 is set for Native resolution'),
'#size' => 10,
'#maxlength' => 10,
'#disabled' => $custom_resolution == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_options']['shrinktheweb_delay'] = array(
'#type' => 'textfield',
'#title' => t('Delay After Load'),
'#default_value' => $custom_delay == 0 ? '' : $config
->get('shrinktheweb_delay'),
'#description' => $custom_delay == 0 ? t('Upgrade required to use this feature') : t('max. 45'),
'#size' => 10,
'#maxlength' => 10,
'#disabled' => $custom_delay == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_options']['shrinktheweb_quality'] = array(
'#type' => 'textfield',
'#title' => t('Quality'),
'#default_value' => $custom_quality == 0 ? '' : $config
->get('shrinktheweb_quality'),
'#description' => $custom_quality == 0 ? t('Upgrade required to use this feature') : t('0 .. 100'),
'#size' => 10,
'#maxlength' => 10,
'#disabled' => $custom_quality == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_adv_options'] = array(
'#type' => 'fieldset',
'#title' => t('ShrinkTheWeb Advanced Options'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['shrinktheweb_adv_options']['shrinktheweb_cache_days'] = array(
'#type' => 'textfield',
'#title' => t('Cache days'),
'#default_value' => $config
->get('shrinktheweb_cache_days'),
'#description' => t('How many days the images are valid in your cache, Enter 0 (zero) to never update screenshots once cached or -1 to disable caching and always use embedded method instead'),
'#size' => 10,
'#maxlength' => 10,
);
$form['shrinktheweb_adv_options']['shrinktheweb_thumbs_folder'] = array(
'#type' => 'textfield',
'#title' => t('Thumbnails folder'),
'#default_value' => $config
->get('shrinktheweb_thumbs_folder'),
'#required' => TRUE,
'#description' => t('This is a subfolder of the "File system path" folder.'),
);
$form['shrinktheweb_adv_options']['shrinktheweb_custom_msg_url'] = array(
'#type' => 'textfield',
'#title' => t('Custom Messages URL'),
'#default_value' => $custom_messages == 0 ? '' : $config
->get('shrinktheweb_custom_msg_url'),
'#description' => $custom_messages == 0 ? t('Upgrade required to use this feature') : t('specify the URL where your custom message images are stored'),
'#size' => 10,
'#maxlength' => 10,
'#disabled' => $custom_messages == 1 ? FALSE : TRUE,
);
$form['shrinktheweb_adv_options']['shrinktheweb_debug'] = array(
'#type' => 'checkbox',
'#title' => t('Debug'),
'#default_value' => $config
->get('shrinktheweb_debug'),
'#description' => t('Store debug info in database'),
);
}
return parent::buildForm($form, $form_state);
}