class InfoForm in Advanced CSS/JS Aggregation 8.4
Same name and namespace in other branches
- 8.2 src/Form/InfoForm.php \Drupal\advagg\Form\InfoForm
- 8.3 src/Form/InfoForm.php \Drupal\advagg\Form\InfoForm
View AdvAgg information for this site.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\advagg\Form\InfoForm uses AdvaggSettersTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of InfoForm
1 file declares its use of InfoForm
- InfoFormTest.php in tests/
src/ Kernel/ Form/ InfoFormTest.php
1 string reference to 'InfoForm'
File
- src/
Form/ InfoForm.php, line 14
Namespace
Drupal\advagg\FormView source
class InfoForm extends ConfigFormBase {
use AdvaggSettersTrait;
/**
* The theme registry service.
*
* @var \Drupal\Core\Theme\Registry
*/
protected $themeRegistry;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The string translation service.
*
* @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface
*/
protected $translation;
/**
* The AdvAgg cache.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
/**
* The Messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/**
* @var \Drupal\advagg\Form\InfoForm
*/
$instance = parent::create($container);
$instance
->setThemeRegistry($container
->get('theme.registry'));
$instance
->setRequestStack($container
->get('request_stack'));
$instance
->setDateFomatter($container
->get('date.formatter'));
$instance
->setStringTranslation($container
->get('string_translation'));
$instance
->setCache($container
->get('cache.advagg'));
return $instance;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'advagg_info';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['tip'] = [
'#markup' => '<p>' . $this
->t('This page provides debugging information. There are no configuration options here.') . '</p>',
];
// Get all hooks and variables.
$core_hooks = $this->themeRegistry
->get();
$advagg_hooks = advagg_hooks_implemented();
// Output html preprocess functions hooks.
$form['theme_info'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Hook Theme Info'),
];
$data = implode("\n", $core_hooks['html']['preprocess functions']);
$form['theme_info']['advagg_theme_info'] = [
'#markup' => '<p>preprocess functions on html.</p><pre>' . $data . '</pre>',
];
$form['hooks_implemented'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Core asset hooks implemented by modules'),
];
// Output all advagg hooks implemented.
foreach ($advagg_hooks as $hook => $values) {
if (empty($values)) {
$form['hooks_implemented'][$hook] = [
'#markup' => '<div><strong>' . $hook . ':</strong> 0</div>',
];
}
else {
$form['hooks_implemented'][$hook] = [
'#markup' => '<div><strong>' . $hook . ':</strong> ' . count($values) . $this
->formatList($values) . '</div>',
];
}
}
// Get info about a file.
$form['get_info_about_agg'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Get detailed info about an optimized file'),
];
$form['get_info_about_agg']['filename'] = [
'#type' => 'textfield',
'#size' => 170,
'#maxlength' => 256,
'#default_value' => '',
'#title' => $this
->t('Filename'),
];
$form['get_info_about_agg']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Lookup Details'),
'#submit' => [
'::getFileInfoSubmit',
],
'#validate' => [
'::getFileInfoValidate',
],
'#ajax' => [
'callback' => '::getFileInfoAjax',
'wrapper' => 'advagg-file-info-ajax',
'effect' => 'fade',
],
];
if ($tip = $this
->getRandomFile()) {
$form['get_info_about_agg']['tip'] = [
'#markup' => '<p>' . $this
->t('Input an optimized filename like "@css_file".', [
'@css_file' => $tip,
]) . '</p>',
];
}
$form['get_info_about_agg']['wrapper'] = [
'#prefix' => "<div id='advagg-file-info-ajax'>",
'#suffix' => "</div>",
];
$form = parent::buildForm($form, $form_state);
unset($form['actions']);
return $form;
}
/**
* Format an indented list from array.
*
* @param array $list
* The array to convert to a string.
* @param int $depth
* (optional) Depth multiplier for indentation.
*
* @return string
* The imploded and spaced array.
*/
private function formatList(array $list, $depth = 1) {
$spacer = '<br />' . str_repeat(' ', 2 * $depth);
$output = $spacer . Xss::filter(implode($spacer, $list), [
'br',
]);
return $output;
}
/**
* Display file info in a drupal message.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function getFileInfoSubmit(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addMessage($this
->getFileInfo($form_state
->getValue('filename')));
}
/**
* Display file info via ajax callback.
*
* @param array $form
* An associative array containing the structure of the form.
*
* @return array
* The file info element.
*/
public function getFileInfoAjax(array &$form) {
return $form['get_info_about_agg']['wrapper'];
}
/**
* Verify that the filename is correct.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function getFileInfoValidate(array $form, FormStateInterface $form_state) {
if (empty($form_state
->getValue('filename'))) {
$form_state
->setErrorByName('filename', $this
->t('Please input a valid optimized filename.'));
}
}
/**
* Get detailed info about the given filename.
*
* @param string $filename
* Name of file to lookup.
*
* @return string
* Detailed info about this file.
*/
private function getFileInfo($filename) {
if (substr_compare($filename, 'css_', 0) || substr_compare($filename, 'js_', 0)) {
$cid = str_replace([
'css_',
'js_',
'.css',
'.js',
], '', $filename);
$cid = substr($cid, 0, strpos($cid, '.'));
if ($cached = $this->cache
->get($cid, TRUE)) {
return print_r($cached->data, TRUE);
}
}
return $this
->t('Optimized file information not found, confirm spelling of the path. Alternatively, that could be an outdated file.');
}
/**
* Get a (pseudo) random optimized file name.
*
* @return bool|string
* The filename or FALSE if no valid files found.
*/
private function getRandomFile() {
// Ensure the directory exists.
$dir = 'public://js/optimized/';
if (!is_dir($dir)) {
return FALSE;
}
if ($handler = opendir($dir)) {
while (($file = readdir($handler)) !== FALSE) {
if (is_file($dir . $file) && pathinfo($file, PATHINFO_EXTENSION) == 'js') {
closedir($handler);
return $file;
}
}
closedir($handler);
}
return FALSE;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdvaggSettersTrait:: |
protected | property | The CSS asset collection optimizer service. | |
AdvaggSettersTrait:: |
protected | property | The File System service. | |
AdvaggSettersTrait:: |
protected | property | The Guzzle HTTP Client. | 1 |
AdvaggSettersTrait:: |
protected | property | The JavaScript asset collection optimizer service. | |
AdvaggSettersTrait:: |
protected | property | The core language manager service. | 1 |
AdvaggSettersTrait:: |
protected | property | The module handler service. | 1 |
AdvaggSettersTrait:: |
protected | property | The private key service. | |
AdvaggSettersTrait:: |
protected | property | The Drupal renderer. | 1 |
AdvaggSettersTrait:: |
protected | property | The state service. | |
AdvaggSettersTrait:: |
protected | property | Obtaining system time. | |
AdvaggSettersTrait:: |
public | function | The set cache backend. | |
AdvaggSettersTrait:: |
public | function | Set CSS asset collection optimizer service. | |
AdvaggSettersTrait:: |
public | function | Set date formatter service. | |
AdvaggSettersTrait:: |
public | function | Set File System service. | |
AdvaggSettersTrait:: |
public | function | Set http client. | |
AdvaggSettersTrait:: |
public | function | Set JavaScript asset collection optimizer service. | |
AdvaggSettersTrait:: |
public | function | Set language manager service. | |
AdvaggSettersTrait:: |
public | function | Set module handler. | |
AdvaggSettersTrait:: |
public | function | Set private key service. | |
AdvaggSettersTrait:: |
public | function | Set renderer. | |
AdvaggSettersTrait:: |
public | function | Set state service. | |
AdvaggSettersTrait:: |
public | function | The theme registry service. | |
AdvaggSettersTrait:: |
public | function | Obtaining system time. | |
ConfigFormBase:: |
public | function |
Form submission handler. Overrides FormInterface:: |
26 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
InfoForm:: |
protected | property |
The AdvAgg cache. Overrides AdvaggSettersTrait:: |
|
InfoForm:: |
protected | property |
The date formatter service. Overrides AdvaggSettersTrait:: |
|
InfoForm:: |
protected | property |
The Messenger service. Overrides MessengerTrait:: |
|
InfoForm:: |
protected | property |
The request stack. Overrides FormBase:: |
|
InfoForm:: |
protected | property |
The theme registry service. Overrides AdvaggSettersTrait:: |
|
InfoForm:: |
protected | property | The string translation service. | |
InfoForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
InfoForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
InfoForm:: |
private | function | Format an indented list from array. | |
InfoForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
InfoForm:: |
private | function | Get detailed info about the given filename. | |
InfoForm:: |
public | function | Display file info via ajax callback. | |
InfoForm:: |
public | function | Display file info in a drupal message. | |
InfoForm:: |
public | function | Verify that the filename is correct. | |
InfoForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
InfoForm:: |
private | function | Get a (pseudo) random optimized file name. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |