Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL)
 {
     $current_url = Url::createFromRequest($request);
     $devel_config = $this->config('devel.settings');
     $form['page_alter'] = array('#type' => 'checkbox', '#title' => t('Display $page array'), '#default_value' => $devel_config->get('page_alter'), '#description' => t('Display $page array from <a href="http://api.drupal.org/api/function/hook_page_alter/7">hook_page_alter()</a> in the messages area of each page.'));
     $form['raw_names'] = array('#type' => 'checkbox', '#title' => t('Display machine names of permissions and modules'), '#default_value' => $devel_config->get('raw_names'), '#description' => t('Display the language-independent machine names of the permissions in mouse-over hints on the <a href=":permissions_url">Permissions</a> page and the module base file names on the Permissions and <a href=":modules_url">Modules</a> pages.', array(':permissions_url' => Url::fromRoute('user.admin_permissions')->toString(), ':modules_url' => Url::fromRoute('system.modules_list')->toString())));
     $error_handlers = devel_get_handlers();
     $form['error_handlers'] = array('#type' => 'select', '#title' => t('Error handlers'), '#options' => array(DEVEL_ERROR_HANDLER_NONE => t('None'), DEVEL_ERROR_HANDLER_STANDARD => t('Standard Drupal'), DEVEL_ERROR_HANDLER_BACKTRACE_DPM => t('Kint backtrace in the message area'), DEVEL_ERROR_HANDLER_BACKTRACE_KINT => t('Kint backtrace above the rendered page')), '#multiple' => TRUE, '#default_value' => empty($error_handlers) ? DEVEL_ERROR_HANDLER_NONE : $error_handlers, '#description' => [['#markup' => $this->t('Select the error handler(s) to use, in case you <a href=":choose">choose to show errors on screen</a>.', [':choose' => $this->url('system.logging_settings')])], ['#theme' => 'item_list', '#items' => [$this->t('<em>None</em> is a good option when stepping through the site in your debugger.'), $this->t('<em>Standard Drupal</em> does not display all the information that is often needed to resolve an issue.'), $this->t('<em>Kint backtrace</em> displays nice debug information when any type of error is noticed, but only to users with the %perm permission.', ['%perm' => t('Access developer information')])]], ['#markup' => $this->t('Depending on the situation, the theme, the size of the call stack and the arguments, etc., some handlers may not display their messages, or display them on the subsequent page. Select <em>Standard Drupal</em> <strong>and</strong> <em>Kint backtrace above the rendered page</em> to maximize your chances of not missing any messages.') . '<br />' . $this->t('Demonstrate the current error handler(s):') . ' ' . $this->l('notice', $current_url->setOption('query', ['demo' => 'notice'])) . ', ' . $this->l('notice+warning', $current_url->setOption('query', ['demo' => 'warning'])) . ', ' . $this->l('notice+warning+error', $current_url->setOption('query', ['demo' => 'error'])) . ' (' . $this->t('The presentation of the @error is determined by PHP.', ['@error' => 'error']) . ')']]);
     $form['error_handlers']['#size'] = count($form['error_handlers']['#options']);
     if ($request->query->has('demo')) {
         if ($request->getMethod() == 'GET') {
             $this->demonstrateErrorHandlers($request->query->get('demo'));
         }
         $request->query->remove('demo');
     }
     $form['rebuild_theme'] = array('#type' => 'checkbox', '#title' => t('Rebuild the theme information like the registry'), '#description' => t('While creating new templates, change the $theme.info.yml and theme_ overrides the theme information needs to be rebuilt.'), '#default_value' => $devel_config->get('rebuild_theme'));
     $dumper = $devel_config->get('devel_dumper');
     $default = $this->dumperManager->isPluginSupported($dumper) ? $dumper : $this->dumperManager->getFallbackPluginId(NULL);
     $form['dumper'] = array('#type' => 'radios', '#title' => $this->t('Variables Dumper'), '#options' => [], '#default_value' => $default, '#description' => $this->t('Select the debugging tool used for formatting and displaying the variables inspected through the debug functions of Devel. You can enable the <a href=":kint_install">Kint module</a> (shipped with Devel) and select the Kint debugging tool for an improved debugging experience. <strong>NOTE</strong>: Some of these plugins require external libraries for to be enabled. Learn how install external libraries with <a href=":url">Composer</a>.', [':url' => 'https://www.drupal.org/node/2404989', ':kint_install' => Url::fromRoute('system.modules_list')->toString()]));
     foreach ($this->dumperManager->getDefinitions() as $id => $definition) {
         $form['dumper']['#options'][$id] = $definition['label'];
         $supported = $this->dumperManager->isPluginSupported($id);
         $form['dumper'][$id]['#disabled'] = !$supported;
         $form['dumper'][$id]['#description'] = ['#type' => 'inline_template', '#template' => '{{ description }}{% if not supported %}<div><small>{% trans %}<strong>Not available</strong>. You may need to install external dependencies for use this plugin.{% endtrans %}</small></div>{% endif %}', '#context' => ['description' => $definition['description'], 'supported' => $supported]];
     }
     return parent::buildForm($form, $form_state);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL)
 {
     $current_path = $request->attributes->get('_system_path');
     $current_url = Url::createFromRequest($request);
     $devel_config = $this->config('devel.settings');
     $form['queries'] = array('#type' => 'fieldset', '#title' => t('Query log'));
     $description = t('Display a log of the database queries needed to generate the current page, and the execution time for each. Also, queries which are repeated during a single page view are summed in the # column, and printed in red since they are candidates for caching.');
     $form['queries']['query_display'] = array('#type' => 'checkbox', '#title' => t('Display query log'), '#default_value' => $devel_config->get('query_display'), '#description' => $description);
     $form['queries']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="query_display"]' => array('checked' => FALSE))));
     $form['queries']['settings']['query_sort'] = array('#type' => 'radios', '#title' => t('Sort query log'), '#default_value' => $devel_config->get('query_sort'), '#options' => array(t('by source'), t('by duration')), '#description' => t('The query table can be sorted in the order that the queries were executed or by descending duration.'));
     $form['queries']['settings']['execution'] = array('#type' => 'textfield', '#title' => t('Slow query highlighting'), '#default_value' => $devel_config->get('execution'), '#size' => 4, '#maxlength' => 4, '#description' => t('Enter an integer in milliseconds. Any query which takes longer than this many milliseconds will be highlighted in the query log. This indicates a possibly inefficient query, or a candidate for caching.'));
     $form['api_url'] = array('#type' => 'textfield', '#title' => t('API Site'), '#default_value' => $devel_config->get('api_url'), '#description' => t('The base URL for your developer documentation links. You might change this if you run <a href="!url">api.module</a> locally.', array('!url' => Url::fromUri('http://drupal.org/project/api')->toString())));
     $form['timer'] = array('#type' => 'checkbox', '#title' => t('Display page timer'), '#default_value' => $devel_config->get('timer'), '#description' => t('Display page execution time in the query log box.'));
     $form['memory'] = array('#type' => 'checkbox', '#title' => t('Display memory usage'), '#default_value' => $devel_config->get('memory'), '#description' => t('Display how much memory is used to generate the current page. This will show memory usage when devel_init() is called and when devel_exit() is called.'));
     $form['redirect_page'] = array('#type' => 'checkbox', '#title' => t('Display redirection page'), '#default_value' => $devel_config->get('redirect_page'), '#description' => t('When a module executes drupal_goto(), the query log and other developer information is lost. Enabling this setting presents an intermediate page to developers so that the log can be examined before continuing to the destination page.'));
     $form['page_alter'] = array('#type' => 'checkbox', '#title' => t('Display $page array'), '#default_value' => $devel_config->get('page_alter'), '#description' => t('Display $page array from <a href="http://api.drupal.org/api/function/hook_page_alter/7">hook_page_alter()</a> in the messages area of each page.'));
     $form['raw_names'] = array('#type' => 'checkbox', '#title' => t('Display machine names of permissions and modules'), '#default_value' => $devel_config->get('raw_names'), '#description' => t('Display the language-independent machine names of the permissions in mouse-over hints on the !Permissions page and the module base file names on the @Permissions and !Modules pages.', array('!Permissions' => $this->l(t('Permissions'), Url::fromRoute('user.admin_permissions')), '@Permissions' => t('Permissions'), '!Modules' => $this->l(t('Modules'), Url::fromRoute('system.modules_list')))));
     $error_handlers = devel_get_handlers();
     $form['error_handlers'] = array('#type' => 'select', '#title' => t('Error handlers'), '#options' => array(DEVEL_ERROR_HANDLER_NONE => t('None'), DEVEL_ERROR_HANDLER_STANDARD => t('Standard Drupal'), DEVEL_ERROR_HANDLER_BACKTRACE_DPM => t('Krumo backtrace in the message area'), DEVEL_ERROR_HANDLER_BACKTRACE_KRUMO => t('Krumo backtrace above the rendered page')), '#multiple' => TRUE, '#default_value' => empty($error_handlers) ? DEVEL_ERROR_HANDLER_NONE : $error_handlers, '#description' => SafeMarkup::set(t('Select the error handler(s) to use, in case you <a href="@choose">choose to show errors on screen</a>.', array('@choose' => $this->url('system.logging_settings'))) . '<ul>' . '<li>' . t('<em>None</em> is a good option when stepping through the site in your debugger.') . '</li>' . '<li>' . t('<em>Standard Drupal</em> does not display all the information that is often needed to resolve an issue.') . '</li>' . '<li>' . t('<em>Krumo backtrace</em> displays nice debug information when any type of error is noticed, but only to users with the %perm permission.', array('%perm' => t('Access developer information'))) . '</li></ul>' . t('Depending on the situation, the theme, the size of the call stack and the arguments, etc., some handlers may not display their messages, or display them on the subsequent page. Select <em>Standard Drupal</em> <strong>and</strong> <em>Krumo backtrace above the rendered page</em> to maximize your chances of not missing any messages.') . '<br />' . t('Demonstrate the current error handler(s):') . ' ' . $this->l('notice', $current_url, array('query' => array('demo' => 'notice'))) . ', ' . $this->l('notice+warning', $current_url, array('query' => array('demo' => 'warning'))) . ', ' . $this->l('notice+warning+error', $current_url, array('query' => array('demo' => 'error'))) . ' ' . t('(The presentation of the @error is determined by PHP.)', array('@error' => 'error'))));
     $form['error_handlers']['#size'] = count($form['error_handlers']['#options']);
     if ($request->query->has('demo')) {
         if ($request->getMethod() == 'GET') {
             $this->demonstrateErrorHandlers($request->query->get('demo'));
         }
         $request->query->remove('demo');
     }
     $options = array('default', 'blue', 'green', 'orange', 'white', 'disabled');
     $form['krumo_skin'] = array('#type' => 'radios', '#title' => t('Krumo display'), '#description' => t('Select a skin for your debug messages or select <em>disabled</em> to display object and array output in standard PHP format.'), '#options' => array_combine($options, $options), '#default_value' => $devel_config->get('krumo_skin'));
     $form['rebuild_theme'] = array('#type' => 'checkbox', '#title' => t('Rebuild the theme information like the registry'), '#description' => t('While creating new templates, change the $theme.info.yml and theme_ overrides the theme information needs to be rebuilt.'), '#default_value' => $devel_config->get('rebuild_theme'));
     $form['use_uncompressed_jquery'] = array('#type' => 'checkbox', '#title' => t('Use uncompressed jQuery'), '#default_value' => $devel_config->get('use_uncompressed_jquery'), '#description' => t("Use a human-readable version of jQuery instead of the minified version that ships with Drupal, to make JavaScript debugging easier."));
     return parent::buildForm($form, $form_state);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function buildUrls(FacetInterface $facet, array $results)
 {
     // No results are found for this facet, so don't try to create urls.
     if (empty($results)) {
         return [];
     }
     // First get the current list of get parameters.
     $get_params = $this->request->query;
     // When adding/removing a filter the number of pages may have changed,
     // possibly resulting in an invalid page parameter.
     $get_params->remove('page');
     // Set the url alias from the the facet object.
     $this->urlAlias = $facet->getUrlAlias();
     $request = $this->request;
     if ($facet->getFacetSource()->getPath()) {
         $request = Request::create($facet->getFacetSource()->getPath());
     }
     $url = Url::createFromRequest($request);
     $url->setOption('attributes', ['rel' => 'nofollow']);
     /** @var \Drupal\facets\Result\ResultInterface[] $results */
     foreach ($results as &$result) {
         // Sets the url for children.
         if ($children = $result->getChildren()) {
             $this->buildUrls($facet, $children);
         }
         $filter_string = $this->urlAlias . self::SEPARATOR . $result->getRawValue();
         $result_get_params = clone $get_params;
         $filter_params = $result_get_params->get($this->filterKey, [], TRUE);
         // If the value is active, remove the filter string from the parameters.
         if ($result->isActive()) {
             foreach ($filter_params as $key => $filter_param) {
                 if ($filter_param == $filter_string) {
                     unset($filter_params[$key]);
                 }
             }
         } else {
             $filter_params[] = $filter_string;
             // Exclude currently active results from the filter params if we are in
             // the show_only_one_result mode.
             if ($facet->getShowOnlyOneResult()) {
                 foreach ($results as $result2) {
                     if ($result2->isActive()) {
                         $active_filter_string = $this->urlAlias . self::SEPARATOR . $result2->getRawValue();
                         foreach ($filter_params as $key2 => $filter_param2) {
                             if ($filter_param2 == $active_filter_string) {
                                 unset($filter_params[$key2]);
                             }
                         }
                     }
                 }
             }
         }
         $result_get_params->set($this->filterKey, array_values($filter_params));
         $url = clone $url;
         $url->setOption('query', $result_get_params->all());
         $result->setUrl($url);
     }
     return $results;
 }
Ejemplo n.º 4
0
 /**
  * Tests the createFromRequest method.
  *
  * @covers ::createFromRequest()
  *
  * @expectedException \Drupal\Core\Routing\MatchingRouteNotFoundException
  * @expectedExceptionMessage No matching route could be found for the request: request_as_a_string
  */
 public function testCreateFromRequest()
 {
     // Mock the request in order to override the __toString() method.
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $request->expects($this->once())->method('__toString')->will($this->returnValue('request_as_a_string'));
     $this->router->expects($this->once())->method('matchRequest')->with($request)->will($this->throwException(new ResourceNotFoundException()));
     $this->assertNull(Url::createFromRequest($request));
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL)
 {
     $current_url = Url::createFromRequest($request);
     $social_lite_config = $this->config('social_lite.settings');
     $form['api_key'] = array('#type' => 'textfield', '#title' => t('ShareThis Publisher Key'), '#default_value' => $social_lite_config->get('api_key'), '#description' => t('Use the ShareThis Publisher Key'));
     $form['use_email'] = array('#type' => 'checkbox', '#title' => t('Email Option'), '#default_value' => $social_lite_config->get('use_email'), '#description' => t('Display "Email" sharing option'));
     $form['use_print'] = array('#type' => 'checkbox', '#title' => t('Print Option'), '#default_value' => $social_lite_config->get('use_print'), '#description' => t('Display "Print" option'));
     $form['logo'] = array('#type' => 'textfield', '#title' => t('URL to logo'), '#default_value' => $social_lite_config->get('logo'), '#description' => t('Path to the Logo relative to the active theme. Used in the ShareThis dialog.'));
     $form['share_icon'] = array('#type' => 'textfield', '#title' => t('URL to share icon'), '#default_value' => $social_lite_config->get('share_icon'), '#description' => t('Path to the icon relative to the active theme. Use only SVG.'));
     $form['email_icon'] = array('#type' => 'textfield', '#title' => t('URL to email icon'), '#default_value' => $social_lite_config->get('email_icon'), '#description' => t('Path to the icon relative to the active theme. Use only SVG.'));
     $form['print_icon'] = array('#type' => 'textfield', '#title' => t('URL to print icon'), '#default_value' => $social_lite_config->get('print_icon'), '#description' => t('Path to the icon relative to the active theme. Use only SVG.'));
     return parent::buildForm($form, $form_state);
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL)
 {
     $current_url = Url::createFromRequest($request);
     $devel_config = $this->config('devel.settings');
     $form['api_url'] = array('#type' => 'textfield', '#title' => t('API Site'), '#default_value' => $devel_config->get('api_url'), '#description' => t('The base URL for your developer documentation links. You might change this if you run <a href=":url">api.module</a> locally.', array(':url' => Url::fromUri('http://drupal.org/project/api')->toString())));
     $form['page_alter'] = array('#type' => 'checkbox', '#title' => t('Display $page array'), '#default_value' => $devel_config->get('page_alter'), '#description' => t('Display $page array from <a href="http://api.drupal.org/api/function/hook_page_alter/7">hook_page_alter()</a> in the messages area of each page.'));
     $form['raw_names'] = array('#type' => 'checkbox', '#title' => t('Display machine names of permissions and modules'), '#default_value' => $devel_config->get('raw_names'), '#description' => t('Display the language-independent machine names of the permissions in mouse-over hints on the <a href=":permissions_url">Permissions</a> page and the module base file names on the Permissions and <a href=":modules_url">Modules</a> pages.', array(':permissions_url' => Url::fromRoute('user.admin_permissions')->toString(), ':modules_url' => Url::fromRoute('system.modules_list')->toString())));
     $error_handlers = devel_get_handlers();
     $form['error_handlers'] = array('#type' => 'select', '#title' => t('Error handlers'), '#options' => array(DEVEL_ERROR_HANDLER_NONE => t('None'), DEVEL_ERROR_HANDLER_STANDARD => t('Standard Drupal'), DEVEL_ERROR_HANDLER_BACKTRACE_DPM => t('Kint backtrace in the message area'), DEVEL_ERROR_HANDLER_BACKTRACE_KINT => t('Kint backtrace above the rendered page')), '#multiple' => TRUE, '#default_value' => empty($error_handlers) ? DEVEL_ERROR_HANDLER_NONE : $error_handlers, '#description' => [['#markup' => $this->t('Select the error handler(s) to use, in case you <a href=":choose">choose to show errors on screen</a>.', [':choose' => $this->url('system.logging_settings')])], ['#theme' => 'item_list', '#items' => [$this->t('<em>None</em> is a good option when stepping through the site in your debugger.'), $this->t('<em>Standard Drupal</em> does not display all the information that is often needed to resolve an issue.'), $this->t('<em>Kint backtrace</em> displays nice debug information when any type of error is noticed, but only to users with the %perm permission.', ['%perm' => t('Access developer information')])]], ['#markup' => $this->t('Depending on the situation, the theme, the size of the call stack and the arguments, etc., some handlers may not display their messages, or display them on the subsequent page. Select <em>Standard Drupal</em> <strong>and</strong> <em>Kint backtrace above the rendered page</em> to maximize your chances of not missing any messages.') . '<br />' . $this->t('Demonstrate the current error handler(s):') . ' ' . $this->l('notice', $current_url->setOption('query', ['demo' => 'notice'])) . ', ' . $this->l('notice+warning', $current_url->setOption('query', ['demo' => 'warning'])) . ', ' . $this->l('notice+warning+error', $current_url->setOption('query', ['demo' => 'error'])) . ' (' . $this->t('The presentation of the @error is determined by PHP.', ['@error' => 'error']) . ')']]);
     $form['error_handlers']['#size'] = count($form['error_handlers']['#options']);
     if ($request->query->has('demo')) {
         if ($request->getMethod() == 'GET') {
             $this->demonstrateErrorHandlers($request->query->get('demo'));
         }
         $request->query->remove('demo');
     }
     $form['rebuild_theme'] = array('#type' => 'checkbox', '#title' => t('Rebuild the theme information like the registry'), '#description' => t('While creating new templates, change the $theme.info.yml and theme_ overrides the theme information needs to be rebuilt.'), '#default_value' => $devel_config->get('rebuild_theme'));
     return parent::buildForm($form, $form_state);
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function buildUrls(FacetInterface $facet, array $results)
 {
     // Create links for all the values.
     // First get the current list of get parameters.
     $get_params = $this->request->query;
     // Set the url alias from the the facet object.
     $this->urlAlias = $facet->getUrlAlias();
     // No results are found for this facet, so don't try to create urls.
     if (empty($results)) {
         return [];
     }
     /** @var \Drupal\facets\Result\ResultInterface $result */
     foreach ($results as &$result) {
         $filter_string = $this->urlAlias . self::SEPARATOR . $result->getRawValue();
         $result_get_params = clone $get_params;
         $filter_params = $result_get_params->get($this->filterKey, [], TRUE);
         // If the value is active, remove the filter string from the parameters.
         if ($result->isActive()) {
             foreach ($filter_params as $key => $filter_param) {
                 if ($filter_param == $filter_string) {
                     unset($filter_params[$key]);
                 }
             }
         } else {
             $filter_params[] = $filter_string;
         }
         $result_get_params->set($this->filterKey, $filter_params);
         $request = $this->request;
         if ($facet->getFacetSource()->getPath()) {
             $request = Request::create($facet->getFacetSource()->getPath());
         }
         $url = Url::createFromRequest($request);
         $url->setOption('query', $result_get_params->all());
         $result->setUrl($url);
     }
     return $results;
 }
Ejemplo n.º 8
0
 /**
  * Submit handler for form buttons that do not complete a form workflow.
  *
  * The Edit View form is a multistep form workflow, but with state managed by
  * the SharedTempStore rather than $form_state->setRebuild(). Without this
  * submit handler, buttons that add or remove displays would redirect to the
  * destination parameter (e.g., when the Edit View form is linked to from a
  * contextual link). This handler can be added to buttons whose form submission
  * should not yet redirect to the destination.
  */
 public function submitDelayDestination($form, FormStateInterface $form_state)
 {
     $request = $this->requestStack->getCurrentRequest();
     $destination = $request->query->get('destination');
     $redirect = $form_state->getRedirect();
     // If there is a destination, and redirects are not explicitly disabled, add
     // the destination as a query string to the redirect and suppress it for the
     // current request.
     if (isset($destination) && $redirect !== FALSE) {
         // Create a valid redirect if one does not exist already.
         if (!$redirect instanceof Url) {
             $redirect = Url::createFromRequest($request);
         }
         // Add the current destination to the redirect unless one exists already.
         $options = $redirect->getOptions();
         if (!isset($options['query']['destination'])) {
             $options['query']['destination'] = $destination;
             $redirect->setOptions($options);
         }
         $form_state->setRedirectUrl($redirect);
         $request->query->remove('destination');
     }
 }
Ejemplo n.º 9
0
 /**
  * Tests that an invalid request will thrown an exception.
  *
  * @covers ::createFromRequest
  *
  * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
  */
 public function testUrlFromRequestInvalid()
 {
     $request = Request::create('/test-path');
     $this->router->expects($this->once())->method('matchRequest')->with($request)->will($this->throwException(new ResourceNotFoundException()));
     $this->assertNull(Url::createFromRequest($request));
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // @todo fix PathValidatorInterface::getUrlIfValid() so we can use it
     //   here. The problem is that we need an exception, not a FALSE
     //   return value. https://www.drupal.org/node/2346695
     if ($this->path->value == '<front>') {
         $url = new Url($this->path->value);
     } else {
         $url = Url::createFromRequest(Request::create("/{$this->path->value}"));
     }
     $this->setRouteName($url->getRouteName());
     $this->setRouteParameters($url->getRouteParameters());
 }