/**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     // Attach campaign JS and CSS.
     $build['#attached']['library'][] = 'mailchimp_campaign/campaign-view';
     // Prepare rendered content.
     /* @var $entity \Drupal\mailchimp_campaign\Entity\MailchimpCampaign */
     $content = $this->renderTemplate($entity->getTemplate());
     $rendered = '';
     foreach ($content as $key => $section) {
         $rendered .= "<h3>{$key}</h3>" . $section;
     }
     // Get the template name.
     $mc_template = mailchimp_campaign_get_template($entity->mc_data['template_id']);
     $mc_template_name = isset($mc_template) ? $mc_template['name'] : '';
     $list_segment_name = 'N/A';
     $list_segments = mailchimp_campaign_get_list_segments($entity->list['id'], 'saved');
     if (isset($entity->mc_data['saved_segment']['id'])) {
         foreach ($list_segments as $list_segment) {
             if ($list_segment['id'] == $entity->mc_data['saved_segment']['id']) {
                 $list_segment_name = $list_segment['name'];
             }
         }
     }
     $list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $entity->list['web_id'], array('attributes' => array('target' => '_blank')));
     $archive_url = Url::fromUri($entity->mc_data['archive_url']);
     $fields = array('subject' => array('label' => t('Subject'), 'value' => $entity->mc_data['subject']), 'list' => array('label' => t('MailChimp List'), 'value' => \Drupal::l($entity->list['name'], $list_url)), 'list_segment' => array('label' => t('List Segment'), 'value' => $list_segment_name), 'from_email' => array('label' => t('From Email'), 'value' => $entity->mc_data['from_email']), 'from_name' => array('label' => t('From Name'), 'value' => $entity->mc_data['from_name']), 'template' => array('label' => t('Template'), 'value' => $mc_template_name), 'type' => array('label' => t('List type'), 'value' => $entity->mc_data['type']), 'status' => array('label' => t('Status'), 'value' => $entity->mc_data['status']), 'emails_sent' => array('label' => t('Emails sent'), 'value' => $entity->mc_data['emails_sent']), 'send_time' => array('label' => t('Send time'), 'value' => $entity->mc_data['send_time']), 'content' => array('label' => t('Rendered template HTML (!archive)', array('!archive' => \Drupal::l('View MailChimp archive', $archive_url, array('attributes' => array('target' => '_blank'))))), 'value' => $rendered));
     foreach ($fields as $key => $field) {
         $build[$key] = array('#prefix' => "<div class=\"field campaign-{$key}\"><h3 class=\"field-label\">{$field['label']}</h3>", '#markup' => "<p>{$field['value']}</p>", '#suffix' => '</div>');
     }
     return $build;
 }
 /**
  * Returns the general help page.
  *
  * @return array
  *   The general help page's content.
  */
 private function generalHelp()
 {
     $paragraphs = array();
     $paragraphs[] = t('You should take the security of your site very seriously.
   Fortunately, Drupal is fairly secure by default.
   The Security Review module automates many of the easy-to-make mistakes that render your site insecure, however it does not automatically make your site impenetrable.
   You should give care to what modules you install and how you configure your site and server.
   Be mindful of who visits your site and what features you expose for their use.');
     $paragraphs[] = t('You can read more about securing your site in the !drupal_org and on !cracking_drupal.
   There are also additional modules you can install to secure or protect your site. Be aware though that the more modules you have running on your site the greater (usually) attack area you expose.', array('!drupal_org' => Drupal::l('drupal.org handbooks', Url::fromUri('http://drupal.org/security/secure-configuration')), '!cracking_drupal' => Drupal::l('CrackingDrupal.com', Url::fromUri('http://crackingdrupal.com'))));
     $paragraphs[] = Drupal::l(t('Drupal.org Handbook: Introduction to security-related contrib modules'), Url::fromUri('http://drupal.org/node/382752'));
     $checks = array();
     foreach (Checklist::getChecks() as $check) {
         // Get the namespace array's reference.
         $check_namespace =& $checks[$check->getMachineNamespace()];
         // Set up the namespace array if not set.
         if (!isset($check_namespace)) {
             $check_namespace['namespace'] = $check->getNamespace();
             $check_namespace['check_links'] = array();
         }
         // Add the link pointing to the check-specific help.
         $check_namespace['check_links'][] = Drupal::l(t($check->getTitle()), Url::fromRoute('security_review.help', array('namespace' => $check->getMachineNamespace(), 'title' => $check->getMachineTitle())));
     }
     return array('#theme' => 'general_help', '#paragraphs' => $paragraphs, '#checks' => $checks);
 }
Beispiel #3
0
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);

    $args = array(
      '@pcre-url' => Url::fromUri('http://www.php.net/manual/en/regexp.reference.character-classes.php')->toString(),
      '@doc-url' => Url::fromUri('https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!Unicode.php/constant/Unicode%3A%3APREG_CLASS_WORD_BOUNDARY/8')->toString(),
    );
    $form['spaces'] = array(
      '#type' => 'textfield',
      '#title' => $this->t('Whitespace characters'),
      '#description' => $this->t('Specify the characters that should be regarded as whitespace and therefore used as word-delimiters. Specify the characters as the inside of a <a href="@pcre-url">PCRE character class</a>. Leave empty to use a <a href="@doc-url">default</a> which should be suitable for most languages with a Latin alphabet.', $args),
      '#default_value' => $this->configuration['spaces'],
    );

    $form['overlap_cjk'] = array(
      '#type' => 'checkbox',
      '#title' => $this->t('Simple CJK handling'),
      '#default_value' => $this->configuration['overlap_cjk'],
      '#description' => $this->t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Does not affect other languages.')
    );

    $form['minimum_word_size'] = array(
      '#type' => 'number',
      '#title' => $this->t('Minimum word length to index'),
      '#default_value' => $this->configuration['minimum_word_size'],
      '#min' => 1,
      '#max' => 1000,
      '#description' => $this->t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).')
    );

    return $form;
  }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('xhprof.config');
     $extension_loaded = $this->profiler->isLoaded();
     if ($extension_loaded) {
         $help = $this->t('Profile requests with the XHProf or uprofiler php extension.');
     } else {
         $help = $this->t('You must enable the !xhprof or !uprofiler php extension.', ['!xhprof' => $this->l('XHProf', Url::fromUri('https://www.drupal.org/node/946182')), '!uprofiler' => $this->l('uprofiler', Url::fromUri('https://github.com/FriendsOfPHP/uprofiler'))]);
     }
     $form['help'] = array('#type' => 'inline_template', '#template' => '<span class="warning">{{ help }}</span>', '#context' => array('help' => $help));
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable profiling of page views.'), '#default_value' => $extension_loaded & $config->get('enabled'), '#disabled' => !$extension_loaded);
     $form['settings'] = array('#title' => $this->t('Profiling settings'), '#type' => 'details', '#open' => TRUE, '#states' => array('invisible' => array('input[name="enabled"]' => array('checked' => FALSE))));
     $form['settings']['extension'] = array('#type' => 'select', '#title' => $this->t('Extension'), '#options' => $this->profiler->getExtensions(), '#default_value' => $config->get('extension'), '#description' => $this->t('Choose the extension to use for profiling. The recommended extension is !uprofiler because it is actively maintained.', ['!uprofiler' => $this->l('uprofiler', Url::fromUri('https://github.com/FriendsOfPHP/uprofiler'))]));
     $form['settings']['exclude'] = array('#type' => 'textarea', '#title' => $this->t('Exclude'), '#default_value' => $config->get('exclude'), '#description' => $this->t('Path to exclude for profiling. One path per line.'));
     $form['settings']['interval'] = array('#type' => 'number', '#title' => 'Profiling interval', '#min' => 0, '#default_value' => $config->get('interval'), '#description' => $this->t('The approximate number of requests between XHProf samples. Leave zero to profile all requests.'));
     $flags = array('FLAGS_CPU' => $this->t('Cpu'), 'FLAGS_MEMORY' => $this->t('Memory'), 'FLAGS_NO_BUILTINS' => $this->t('Exclude PHP builtin functions'));
     $form['settings']['flags'] = array('#type' => 'checkboxes', '#title' => 'Profile', '#options' => $flags, '#default_value' => $config->get('flags'), '#description' => $this->t('Flags to choose what profile.'));
     $form['settings']['exclude_indirect_functions'] = array('#type' => 'checkbox', '#title' => 'Exclude indirect functions', '#default_value' => $config->get('exclude_indirect_functions'), '#description' => $this->t('Exclude functions like %call_user_func and %call_user_func_array.', array('%call_user_func' => 'call_user_func', '%call_user_func_array' => 'call_user_func_array')));
     $options = $this->storageManager->getStorages();
     $form['settings']['storage'] = array('#type' => 'radios', '#title' => $this->t('Profile storage'), '#default_value' => $config->get('storage'), '#options' => $options, '#description' => $this->t('Choose the storage class.'));
     if ($this->moduleHandler->moduleExists('webprofiler')) {
         $form['webprofiler'] = array('#title' => $this->t('Webprofiler integration'), '#type' => 'details', '#open' => TRUE, '#states' => array('invisible' => array('input[name="enabled"]' => array('checked' => FALSE))));
         $form['webprofiler']['show_summary_toolbar'] = array('#type' => 'checkbox', '#title' => $this->t('Show summary data in toolbar.'), '#default_value' => $config->get('show_summary_toolbar'), '#description' => $this->t('Show data from the overall summary directly into the Webprofiler toolbar. May slow down the toolbar rendering.'));
     }
     return parent::buildForm($form, $form_state);
 }
Beispiel #5
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'));
     $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);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $entity = NULL, $bundle = NULL)
 {
     $this->entity_type = $entity;
     $this->bundle_type = $bundle;
     $config = $this->config('xmlsitemap.settings');
     $request = $this->getRequest();
     if (!$request->isXmlHttpRequest() && ($admin_path = xmlsitemap_get_bundle_path($entity, $bundle))) {
         // If this is a non-ajax form, redirect to the bundle administration page.
         $destination = drupal_get_destination();
         $request->query->remove('destination');
         $url = Url::fromUri($admin_path, array('query' => array($destination)));
         return new RedirectResponse($url);
     } else {
         $form['#title'] = $this->t('@bundle XML sitemap settings', array('@bundle' => $bundle));
     }
     xmlsitemap_add_link_bundle_settings($form, $form_state, $entity, $bundle);
     $form['xmlsitemap']['#type'] = 'markup';
     $form['xmlsitemap']['#value'] = '';
     $form['xmlsitemap']['#access'] = TRUE;
     $form['xmlsitemap']['#show_message'] = TRUE;
     $destination = $request->get('destination');
     $form['actions']['cancel'] = array('#type' => 'link', '#title' => $this->t('Cancel'), '#href' => isset($destination) ? $destination : 'admin/config/search/xmlsitemap/settings', '#weight' => 10);
     $form = parent::buildForm($form, $form_state);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = [];
     $thumb_image_style = $this->getSetting('thumbnail_image_style');
     $popup_image_style = $this->getSetting('popup_image_style');
     $gallery_type = $this->getSetting('gallery_type');
     $files = $this->getEntitiesToView($items, $langcode);
     foreach ($files as $delta => $file) {
         $image_uri = $file->getFileUri();
         $popup_image_path = !empty($popup_image_style) ? ImageStyle::load($popup_image_style)->buildUrl($image_uri) : $image_uri;
         // Depending on the outcome of https://www.drupal.org/node/2622586,
         // Either a class will need to be added to the $url object,
         // Or a custom theme function might be needed to do so.
         // For the time being, 'a' is used as the delegate in magnific-popup.js.
         $url = Url::fromUri(file_create_url($popup_image_path));
         $item = $file->_referringItem;
         $item_attributes = $file->_attributes;
         unset($file->_attributes);
         $item_attributes['class'][] = 'mfp-thumbnail';
         if ($gallery_type === 'first_item' && $delta > 0) {
             $elements[$delta] = ['#theme' => 'image_formatter', '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]];
         } else {
             $elements[$delta] = ['#theme' => 'image_formatter', '#item' => $item, '#item_attributes' => $item_attributes, '#image_style' => $thumb_image_style, '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]];
         }
     }
     return $elements;
 }
Beispiel #8
0
 /**
  * Performs various tests on nodes and their REST API.
  */
 public function testNodes()
 {
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     $this->enableNodeConfiguration('GET', 'view');
     $node = $this->entityCreate('node');
     $node->save();
     $this->httpRequest($node->urlInfo(), 'GET', NULL, $this->defaultMimeType);
     $this->assertResponse(200);
     $this->assertHeader('Content-type', $this->defaultMimeType);
     // Also check that JSON works and the routing system selects the correct
     // REST route.
     $this->enableService('entity:node', 'GET', 'json');
     $this->httpRequest($node->urlInfo(), 'GET', NULL, 'application/json');
     $this->assertResponse(200);
     $this->assertHeader('Content-type', 'application/json');
     // Check that a simple PATCH update to the node title works as expected.
     $this->enableNodeConfiguration('PATCH', 'update');
     // Create a PATCH request body that only updates the title field.
     $new_title = $this->randomString();
     $data = array('_links' => array('type' => array('href' => Url::fromUri('base:rest/type/node/resttest', array('absolute' => TRUE))->toString())), 'title' => array(array('value' => $new_title)));
     $serialized = $this->container->get('serializer')->serialize($data, $this->defaultFormat);
     $this->httpRequest($node->urlInfo(), 'PATCH', $serialized, $this->defaultMimeType);
     $this->assertResponse(204);
     // Reload the node from the DB and check if the title was correctly updated.
     $node_storage->resetCache(array($node->id()));
     $updated_node = $node_storage->load($node->id());
     $this->assertEqual($updated_node->getTitle(), $new_title);
     // Make sure that the UUID of the node has not changed.
     $this->assertEqual($node->get('uuid')->getValue(), $updated_node->get('uuid')->getValue(), 'UUID was not changed.');
 }
 /**
  * Renders a list with all custom links.
  *
  * @return array
  *   The list to be rendered.
  */
 public function render()
 {
     $build['xmlsitemap_add_custom'] = array('#type' => 'link', '#title' => t('Add custom link'), '#href' => 'admin/config/search/xmlsitemap/custom/add');
     $header = array('loc' => array('data' => t('Location'), 'field' => 'loc', 'sort' => 'asc'), 'priority' => array('data' => t('Priority'), 'field' => 'priority'), 'changefreq' => array('data' => t('Change frequency'), 'field' => 'changefreq'), 'language' => array('data' => t('Language'), 'field' => 'language'), 'operations' => array('data' => t('Operations')));
     $rows = array();
     $destination = drupal_get_destination();
     $query = db_select('xmlsitemap');
     $query->fields('xmlsitemap');
     $query->condition('type', 'custom');
     $query->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')->limit(50);
     $query->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')->orderByHeader($header);
     $result = $query->execute();
     foreach ($result as $link) {
         $language = $this->languageManager->getLanguage($link->language);
         $row = array();
         $row['loc'] = $this->l($link->loc, Url::fromUri($link->loc));
         $row['priority'] = number_format($link->priority, 1);
         $row['changefreq'] = $link->changefreq ? drupal_ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : t('None');
         if (isset($header['language'])) {
             $row['language'] = t($language->name);
         }
         $operations['edit'] = array('title' => t('Edit'), 'route_name' => 'xmlsitemap_custom.edit', 'route_parameters' => array('link' => $link->id));
         $operations['delete'] = array('title' => t('Delete'), 'route_name' => 'xmlsitemap_custom.delete', 'route_parameters' => array('link' => $link->id));
         $row['operations'] = array('data' => array('#type' => 'operations', '#theme' => 'links', '#links' => $operations, '#attributes' => array('class' => array('links', 'inline'))));
         $rows[] = $row;
     }
     // @todo Convert to tableselect
     $build['xmlsitemap_custom_table'] = array('#type' => 'tableselect', '#theme' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('No custom links available. <a href="@custom_link">Add custom link</a>', array('@custom_link' => Url::fromRoute('xmlsitemap_custom.add', [], array('query' => $destination)))));
     $build['xmlsitemap_custom_pager'] = array('#theme' => 'pager');
     return $build;
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function getElement(array &$form, FormStateInterface $form_state)
 {
     // Construct the group elements.
     $group = $this->getGroup($form, $form_state);
     $plugin_id = $this->getPluginId();
     if (!isset($group->{$plugin_id})) {
         // Set properties from the plugin definition.
         foreach ($this->getElementProperties() as $name => $value) {
             $group->{$plugin_id}->setProperty($name, $value);
         }
         // Set default value from the stored form state value or theme setting.
         $default_value = $form_state->getValue($plugin_id, $this->theme->getSetting($plugin_id));
         $group->{$plugin_id}->setProperty('default_value', $default_value);
         // Append additional "see" link references to the description.
         $description = (string) $group->{$plugin_id}->getProperty('description') ?: '';
         /** @var \Drupal\Core\Render\Renderer $renderer */
         $renderer = \Drupal::service('renderer');
         $links = [];
         foreach ($this->pluginDefinition['see'] as $url => $title) {
             $link = ['#type' => 'link', '#url' => Url::fromUri($url), '#title' => $title, '#attributes' => ['target' => '_blank']];
             $links[] = (string) $renderer->render($link);
         }
         if (!empty($links)) {
             $description .= '<br>';
             $description .= t('See also:');
             $description .= ' ' . implode(', ', $links);
             $group->{$plugin_id}->setProperty('description', $description);
         }
     }
     return $group->{$plugin_id};
 }
 /**
  * Assert that an outbound path is altered to an expected value.
  *
  * @param $original
  *   A string with the original path that is run through generateFrommPath().
  * @param $final
  *   A string with the expected result after generateFrommPath().
  * @return
  *   TRUE if $original was correctly altered to $final, FALSE otherwise.
  */
 protected function assertUrlOutboundAlter($original, $final)
 {
     // Test outbound altering.
     $result = $this->container->get('url_generator')->generateFromPath($original);
     $final = Url::fromUri('internal:/' . $final)->toString();
     $this->assertIdentical($result, $final, format_string('Altered outbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
 }
Beispiel #12
0
 /**
  * Gets the list of links used by this field.
  *
  * @return array
  *   The links which are used by the render function.
  */
 protected function getLinks()
 {
     $links = array();
     foreach ($this->options['fields'] as $field) {
         if (empty($this->view->field[$field]->last_render_text)) {
             continue;
         }
         $title = $this->view->field[$field]->last_render_text;
         $path = '';
         $url = NULL;
         if (!empty($this->view->field[$field]->options['alter']['path'])) {
             $path = $this->view->field[$field]->options['alter']['path'];
         } elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof UrlObject) {
             $url = $this->view->field[$field]->options['alter']['url'];
         }
         // Make sure that tokens are replaced for this paths as well.
         $tokens = $this->getRenderTokens(array());
         $path = strip_tags(Html::decodeEntities($this->viewsTokenReplace($path, $tokens)));
         $links[$field] = array('url' => $path ? UrlObject::fromUri('internal:/' . $path) : $url, 'title' => $title);
         if (!empty($this->options['destination'])) {
             $links[$field]['query'] = \Drupal::destination()->getAsArray();
         }
     }
     return $links;
 }
Beispiel #13
0
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);

    $form['title'] = array(
      '#type' => 'checkbox',
      '#title' => $this->t('Index title attribute'),
      '#description' => $this->t('If set, the contents of title attributes will be indexed.'),
      '#default_value' => $this->configuration['title'],
    );

    $form['alt'] = array(
      '#type' => 'checkbox',
      '#title' => $this->t('Index alt attribute'),
      '#description' => $this->t('If set, the alternative text of images will be indexed.'),
      '#default_value' => $this->configuration['alt'],
    );

    $dumper = new Dumper();
    $tags = $dumper->dump($this->configuration['tags'], 2);
    $tags = str_replace('\r\n', "\n", $tags);
    $tags = str_replace('"', '', $tags);

    $t_args['@url'] = Url::fromUri('https://en.wikipedia.org/wiki/YAML')->toString();
    $form['tags'] = array(
      '#type' => 'textarea',
      '#title' => $this->t('Tag boosts'),
      '#description' => $this->t('Specify special boost values for certain HTML elements, in <a href="@url">YAML file format</a>. The boost values of nested elements are multiplied, elements not mentioned will have the default boost value of 1. Assign a boost of 0 to ignore the text content of that HTML element.', $t_args),
      '#default_value' => $tags,
    );

    return $form;
  }
Beispiel #14
0
 /**
  * Tests the menu functionality.
  */
 function testMenus()
 {
     $this->drupalPlaceBlock('system_menu_block:main');
     // Create a view with a page display and a menu link in the Main Menu.
     $view = array();
     $view['label'] = $this->randomMachineName(16);
     $view['id'] = strtolower($this->randomMachineName(16));
     $view['description'] = $this->randomMachineName(16);
     $view['page[create]'] = 1;
     $view['page[title]'] = $this->randomMachineName(16);
     $view['page[path]'] = $this->randomMachineName(16);
     $view['page[link]'] = 1;
     $view['page[link_properties][menu_name]'] = 'main';
     $view['page[link_properties][title]'] = $this->randomMachineName(16);
     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
     // Make sure there is a link to the view from the front page (where we
     // expect the main menu to display).
     $this->drupalGet('');
     $this->assertResponse(200);
     $this->assertLink($view['page[link_properties][title]']);
     $this->assertLinkByHref(Url::fromUri('base:' . $view['page[path]'])->toString());
     // Make sure the link is associated with the main menu.
     /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
     $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
     /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
     $link = $menu_link_manager->createInstance('views_view:views.' . $view['id'] . '.page_1');
     $url = $link->getUrlObject();
     $this->assertEqual($url->getRouteName(), 'view.' . $view['id'] . '.page_1', SafeMarkup::format('Found a link to %path in the main menu', array('%path' => $view['page[path]'])));
     $metadata = $link->getMetaData();
     $this->assertEqual(array('view_id' => $view['id'], 'display_id' => 'page_1'), $metadata);
 }
Beispiel #15
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);
 }
Beispiel #16
0
 /**
  * Tests the normalize function.
  */
 public function testNormalize()
 {
     $target_entity_de = EntityTest::create(array('langcode' => 'de', 'field_test_entity_reference' => NULL));
     $target_entity_de->save();
     $target_entity_en = EntityTest::create(array('langcode' => 'en', 'field_test_entity_reference' => NULL));
     $target_entity_en->save();
     // Create a German entity.
     $values = array('langcode' => 'de', 'name' => $this->randomMachineName(), 'field_test_text' => array('value' => $this->randomMachineName(), 'format' => 'full_html'), 'field_test_entity_reference' => array('target_id' => $target_entity_de->id()));
     // Array of translated values.
     $translation_values = array('name' => $this->randomMachineName(), 'field_test_entity_reference' => array('target_id' => $target_entity_en->id()));
     $entity = EntityTest::create($values);
     $entity->save();
     // Add an English value for name and entity reference properties.
     $entity->addTranslation('en')->set('name', array(0 => array('value' => $translation_values['name'])));
     $entity->getTranslation('en')->set('field_test_entity_reference', array(0 => $translation_values['field_test_entity_reference']));
     $entity->save();
     $type_uri = Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString();
     $relation_uri = Url::fromUri('base:rest/relation/entity_test/entity_test/field_test_entity_reference', array('absolute' => TRUE))->toString();
     $expected_array = array('_links' => array('curies' => array(array('href' => '/relations', 'name' => 'site', 'templated' => TRUE)), 'self' => array('href' => $this->getEntityUri($entity)), 'type' => array('href' => $type_uri), $relation_uri => array(array('href' => $this->getEntityUri($target_entity_de), 'lang' => 'de'), array('href' => $this->getEntityUri($target_entity_en), 'lang' => 'en'))), '_embedded' => array($relation_uri => array(array('_links' => array('self' => array('href' => $this->getEntityUri($target_entity_de)), 'type' => array('href' => $type_uri)), 'uuid' => array(array('value' => $target_entity_de->uuid())), 'lang' => 'de'), array('_links' => array('self' => array('href' => $this->getEntityUri($target_entity_en)), 'type' => array('href' => $type_uri)), 'uuid' => array(array('value' => $target_entity_en->uuid())), 'lang' => 'en'))), 'id' => array(array('value' => $entity->id())), 'uuid' => array(array('value' => $entity->uuid())), 'langcode' => array(array('value' => 'de')), 'name' => array(array('value' => $values['name'], 'lang' => 'de'), array('value' => $translation_values['name'], 'lang' => 'en')), 'field_test_text' => array(array('value' => $values['field_test_text']['value'], 'format' => $values['field_test_text']['format'])));
     $normalized = $this->serializer->normalize($entity, $this->format);
     $this->assertEqual($normalized['_links']['self'], $expected_array['_links']['self'], 'self link placed correctly.');
     // @todo Test curies.
     // @todo Test type.
     $this->assertEqual($normalized['id'], $expected_array['id'], 'Internal id is exposed.');
     $this->assertEqual($normalized['uuid'], $expected_array['uuid'], 'Non-translatable fields is normalized.');
     $this->assertEqual($normalized['name'], $expected_array['name'], 'Translatable field with multiple language values is normalized.');
     $this->assertEqual($normalized['field_test_text'], $expected_array['field_test_text'], 'Field with properties is normalized.');
     $this->assertEqual($normalized['_embedded'][$relation_uri], $expected_array['_embedded'][$relation_uri], 'Entity reference field is normalized.');
     $this->assertEqual($normalized['_links'][$relation_uri], $expected_array['_links'][$relation_uri], 'Links are added for entity reference field.');
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     global $base_url;
     $block_url = Url::fromRoute('block.admin_display');
     $page_url = Url::fromUri($base_url . '/' . $entity->settings['path']);
     $modes = NULL;
     $mc_lists = mailchimp_get_lists();
     switch ($entity->mode) {
         case MAILCHIMP_SIGNUP_BLOCK:
             $modes = \Drupal::l(t('Block'), $block_url);
             $block_only = TRUE;
             break;
         case MAILCHIMP_SIGNUP_PAGE:
             $modes = \Drupal::l(t('Page'), $page_url);
             break;
         case MAILCHIMP_SIGNUP_BOTH:
             $modes = \Drupal::l(t('Block'), $block_url) . ' and ' . \Drupal::l(t('Page'), $page_url);
             break;
     }
     $list_labels = array();
     foreach ($entity->mc_lists as $list_id) {
         if (!empty($list_id)) {
             $list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $mc_lists[$list_id]['web_id'], array('attributes' => array('target' => '_blank')));
             $list_labels[] = \Drupal::l($mc_lists[$list_id]['name'], $list_url);
         }
     }
     $row['label'] = $this->getLabel($entity) . ' (Machine name: ' . $entity->id() . ')';
     $row['display_modes'] = $modes;
     $row['lists'] = implode(', ', $list_labels);
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['help'] = array('#markup' => t('By default, only the "Free order" payment method is listed here. To see additional payment methods you must <a href="@install">install additional modules</a>. The "Payment Method Pack" module that comes with Ubercart provides "Check" and "COD" payment methods. The "Credit Card" module that comes with Ubercart provides a credit card payment method, although you will need an additional module to provide a payment gateway for your credit card. For more information about payment methods and settings please read the <a href="@doc">Ubercart Documentation</a>.', ['@install' => Url::fromRoute('system.modules_list')->toString(), '@doc' => Url::fromUri('http://www.drupal.org/documentation/modules/ubercart')->toString()]));
     $form['methods'] = array('#type' => 'table', '#header' => array(t('Payment method'), t('List position'), t('Operations')), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'uc-payment-method-weight')));
     foreach ($this->paymentMethodManager->getDefinitions() as $id => $method) {
         $form['methods'][$id]['#attributes']['class'][] = 'draggable';
         $form['methods'][$id]['status'] = array('#type' => 'checkbox', '#title' => SafeMarkup::checkPlain($method['name']), '#default_value' => $method['checkout']);
         $form['methods'][$id]['weight'] = array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $method['name'])), '#title_display' => 'invisible', '#default_value' => $method['weight'], '#attributes' => array('class' => array('uc-payment-method-weight')));
         if (empty($method['no_gateway'])) {
             $gateways = _uc_payment_gateway_list($id, TRUE);
             $options = array();
             foreach ($gateways as $gateway_id => $gateway) {
                 $options[$gateway_id] = $gateway['title'];
             }
             if ($options) {
                 $form['methods'][$id]['status']['#title'] .= ' (' . t('includes %gateways', array('%gateways' => implode(', ', $options))) . ')';
             }
         }
         $links = array();
         if (!empty($method['settings_form'])) {
             $links['settings'] = array('title' => t('Settings'), 'url' => Url::fromRoute('uc_payment.method_settings', ['method' => $id]));
         }
         // $links['conditions'] = array(
         //   'title' => t('Conditions'),
         //   'url' => Url::fromRoute('admin/store/config/payment/manage/uc_payment_method_', ['method' => $id]),
         // );
         $form['methods'][$id]['settings'] = array('#type' => 'operations', '#links' => $links);
     }
     return parent::buildForm($form, $form_state);
 }
Beispiel #19
0
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);

    $form['ignorable'] = array(
      '#type' => 'textfield',
      '#title' => $this->t('Strip by regular expression'),
      '#description' => $this->t('Specify characters which should be removed from fulltext fields and search strings, as a <a href="@url">PCRE regular expression</a>.', array('@url' => Url::fromUri('http://php.net/manual/en/reference.pcre.pattern.syntax.php')->toString())),
      '#default_value' => $this->configuration['ignorable'],
      '#maxlength' => 1000,
    );

    $character_sets = $this->getCharacterSets();
    $form['strip'] = array(
      '#type' => 'details',
      '#title' => $this->t('Strip by character property'),
      '#description' => $this->t('Specify <a href="@url">Unicode character properties</a> of characters to be ignored.', array('@url' => Url::fromUri('http://www.fileformat.info/info/unicode/category/index.htm')->toString())),
      '#open' => FALSE,
      '#maxlength' => 300,

    );
    $form['strip']['character_sets'] = array(
      '#type' => 'checkboxes',
      '#title' => $this->t('Ignored character properties'),
      '#options' => $character_sets,
      '#default_value' => $this->configuration['strip']['character_sets'],
      '#multiple' => TRUE,
    );

    return $form;
  }
 /**
  * Tests the output drupal_render() for some elementary input values.
  */
 function testDrupalRenderBasics()
 {
     $types = array(array('name' => 'null', 'value' => NULL, 'expected' => ''), array('name' => 'no value', 'expected' => ''), array('name' => 'empty string', 'value' => '', 'expected' => ''), array('name' => 'no access', 'value' => array('#markup' => 'foo', '#access' => FALSE), 'expected' => ''), array('name' => 'access denied via callback', 'value' => array('#markup' => 'foo', '#access_callback' => 'is_bool'), 'expected' => ''), array('name' => 'access granted via callback', 'value' => array('#markup' => 'foo', '#access_callback' => 'is_array'), 'expected' => 'foo'), array('name' => 'access FALSE is honored', 'value' => array('#markup' => 'foo', '#access' => FALSE, '#access_callback' => 'is_array'), 'expected' => ''), array('name' => 'previously printed', 'value' => array('#markup' => 'foo', '#printed' => TRUE), 'expected' => ''), array('name' => 'printed in prerender', 'value' => array('#markup' => 'foo', '#pre_render' => array('common_test_drupal_render_printing_pre_render')), 'expected' => ''), array('name' => '#theme and #theme_wrappers basic', 'value' => array('#theme' => 'common_test_foo', '#foo' => 'foo', '#bar' => 'bar', '#theme_wrappers' => array('container'), '#attributes' => array('class' => array('baz'))), 'expected' => '<div class="baz">foobar</div>' . "\n"), array('name' => '#theme and #theme_wrappers attribute disambiguation', 'value' => array('#type' => 'link', '#theme_wrappers' => array('container' => array('#attributes' => array('class' => array('baz')))), '#attributes' => array('id' => 'foo'), '#url' => Url::fromUri('http://drupal.org'), '#title' => 'bar'), 'expected' => '<div class="baz"><a href="http://drupal.org" id="foo">bar</a></div>' . "\n"), array('name' => '#theme_wrappers attribute disambiguation with undefined #theme attribute', 'value' => array('#type' => 'link', '#url' => Url::fromUri('http://drupal.org'), '#title' => 'foo', '#theme_wrappers' => array('container' => array('#attributes' => array('class' => array('baz'))))), 'expected' => '<div class="baz"><a href="http://drupal.org">foo</a></div>' . "\n"), array('name' => 'Two #theme_wrappers container hooks with different attributes', 'value' => array('#attributes' => array('class' => array('foo')), '#theme_wrappers' => array('container' => array('#attributes' => array('class' => array('bar'))), 'container')), 'expected' => '<div class="foo"><div class="bar"></div>' . "\n" . '</div>' . "\n"), array('name' => '#theme_wrappers implements an array style theme hook suggestion', 'value' => array('#theme_wrappers' => array(array('container')), '#attributes' => array('class' => array('foo'))), 'expected' => '<div class="foo"></div>' . "\n"), array('name' => 'basic #markup based renderable array', 'value' => array('#markup' => 'foo'), 'expected' => 'foo'), array('name' => '#markup fallback for #theme suggestion not implemented', 'value' => array('#theme' => array('suggestionnotimplemented'), '#markup' => 'foo'), 'expected' => 'foo'), array('name' => '#markup fallback for child elements, #theme suggestion not implemented', 'value' => array('#theme' => array('suggestionnotimplemented'), 'child' => array('#markup' => 'foo')), 'expected' => 'foo'), array('name' => 'Avoid #markup if #theme is implemented but returns an empty string', 'value' => array('#theme' => array('common_test_empty'), '#markup' => 'foo'), 'expected' => ''), array('name' => 'Avoid rendering child elements if #theme is implemented but returns an empty string', 'value' => array('#theme' => array('common_test_empty'), 'child' => array('#markup' => 'foo')), 'expected' => ''), array('name' => '#theme is not set, #children is not set and array has children', 'value' => array('child' => array('#markup' => 'bar')), 'expected' => 'bar'), array('name' => '#theme is not set, #children is an empty string and array has children', 'value' => array('#children' => '', 'child' => array('#markup' => 'bar')), 'expected' => 'bar'), array('name' => '#theme is not set, #children is set and array has children', 'value' => array('#children' => 'foo', 'child' => array('#markup' => 'bar')), 'expected' => 'foo'), array('name' => '#theme is implemented, #children is set and array has children', 'value' => array('#theme' => 'common_test_foo', '#children' => 'baz', 'child' => array('#markup' => 'boo')), 'expected' => 'foobar'), array('name' => '#theme is implemented, #render_children is TRUE, #children is empty and array has children', 'value' => array('#theme' => 'common_test_foo', '#children' => '', '#render_children' => TRUE, 'child' => array('#markup' => 'boo')), 'expected' => 'boo'), array('name' => '#theme is implemented, #render_children is TRUE, #children is set and array has children', 'value' => array('#theme' => 'common_test_foo', '#children' => 'baz', '#render_children' => TRUE, 'child' => array('#markup' => 'boo')), 'expected' => 'baz'));
     foreach ($types as $type) {
         $this->assertIdentical(drupal_render($type['value']), $type['expected'], '"' . $type['name'] . '" input rendered correctly by drupal_render().');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL)
 {
     $config = $this->config('easychart.settings');
     $load_defaults = FALSE;
     // Get defaults.
     foreach ($this->getDefaults() as $default) {
         // Verify default options.
         $default_value = $config->get($default);
         if (empty($default_value)) {
             // Set flag to true.
             $load_defaults = TRUE;
             $form['#attached']['drupalSettings']['easychart'][$default] = TRUE;
         }
     }
     if ($load_defaults) {
         $form['#attached']['library'][] = 'easychart/easychart.defaults';
         $form['#attached']['library'][] = 'easychart/lib.easycharts.full';
     }
     $options = $config->get('options');
     $form['options'] = ['#type' => 'textarea', '#title' => $this->t('Available options'), '#description' => $this->t('These Highcharts options will be configurable in the Easychart interface when creating/editing a chart. See <a href="@url" target="_blank">http://api.highcharts.com/highcharts</a> for all available options.', array('@url' => Url::fromUri('http://api.highcharts.com/highcharts')->toUriString())), '#default_value' => $options, '#attributes' => array('class' => array('easychart-options')), '#rows' => 15];
     $form['templates'] = ['#type' => 'textarea', '#title' => t('Available templates'), '#default_value' => $config->get('templates'), '#description' => t("These templates will be selectable in the Easychart interface when creating/editing a chart."), '#attributes' => array('class' => array('easychart-templates')), '#rows' => 15];
     $form['presets'] = ['#type' => 'textarea', '#title' => t('Presets'), '#default_value' => $config->get('presets'), '#description' => $this->t('Presets for every Easychart chart. If these preset are also mentioned in the available options, they will be shown, but not editable.'), '#attributes' => array('class' => array('easychart-presets')), '#rows' => 10];
     $interval = array(3600, 10800, 21600, 32400, 43200, 86400, 172800);
     $form['url_update_frequency'] = ['#type' => 'select', '#title' => t('Update frequency'), '#options' => array(0 => t('Never')) + array_map([\Drupal::service('date.formatter'), 'formatInterval'], array_combine($interval, $interval)), '#default_value' => $config->get('url_update_frequency'), '#description' => $this->t('When to update the data for charts using a CSV URL.'), '#rows' => 10];
     $form['actions']['reset'] = ['#type' => 'submit', '#value' => t('Reset to defaults'), '#submit' => array('::resetForm'), '#limit_validation_errors' => array(), '#weight' => 100];
     return parent::buildForm($form, $form_state);
 }
 /**
  * Assert that active trail exists in a menu tree output.
  *
  * @param array $tree
  *   An associative array whose keys are link paths and whose
  *   values are link titles (not sanitized) of an expected active trail in a
  *   menu tree output on the page.
  * @param bool $last_active
  *   Whether the last link in $tree is expected to be active (TRUE)
  *   or just to be in the active trail (FALSE).
  */
 protected function assertMenuActiveTrail($tree, $last_active)
 {
     end($tree);
     $active_link_path = key($tree);
     $active_link_title = array_pop($tree);
     $xpath = '';
     if ($tree) {
         $i = 0;
         foreach ($tree as $link_path => $link_title) {
             $part_xpath = !$i ? '//' : '/following-sibling::ul/descendant::';
             $part_xpath .= 'li[contains(@class, :class)]/a[contains(@href, :href) and contains(text(), :title)]';
             $part_args = array(':class' => 'menu-item--active-trail', ':href' => Url::fromUri('base:' . $link_path)->toString(), ':title' => $link_title);
             $xpath .= $this->buildXPathQuery($part_xpath, $part_args);
             $i++;
         }
         $elements = $this->xpath($xpath);
         $this->assertTrue(!empty($elements), 'Active trail to current page was found in menu tree.');
         // Append prefix for active link asserted below.
         $xpath .= '/following-sibling::ul/descendant::';
     } else {
         $xpath .= '//';
     }
     $xpath_last_active = $last_active ? 'and contains(@class, :class-active)' : '';
     $xpath .= 'li[contains(@class, :class-trail)]/a[contains(@href, :href) ' . $xpath_last_active . 'and contains(text(), :title)]';
     $args = array(':class-trail' => 'menu-item--active-trail', ':class-active' => 'is-active', ':href' => Url::fromUri('base:' . $active_link_path)->toString(), ':title' => $active_link_title);
     $elements = $this->xpath($xpath, $args);
     $this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', array('%title' => $active_link_title, '%tree' => implode(' » ', $tree))));
 }
 /**
  * Assert that a trail exists in the internal browser.
  *
  * @param array $trail
  *   An associative array whose keys are expected breadcrumb link paths and
  *   whose values are expected breadcrumb link texts (not sanitized).
  */
 protected function assertBreadcrumbParts($trail)
 {
     // Compare paths with actual breadcrumb.
     $parts = $this->getBreadcrumbParts();
     $pass = TRUE;
     // There may be more than one breadcrumb on the page. If $trail is empty
     // this test would go into an infinite loop, so we need to check that too.
     while ($trail && !empty($parts)) {
         foreach ($trail as $path => $title) {
             // If the path is empty, generate the path from the <front> route.  If
             // the path does not start with a leading slash, then run it through
             // Url::fromUri('base:')->toString() to get the correct base
             // prepended.
             if ($path == '') {
                 $url = Url::fromRoute('<front>')->toString();
             } elseif ($path[0] != '/') {
                 $url = Url::fromUri('base:' . $path)->toString();
             } else {
                 $url = $path;
             }
             $part = array_shift($parts);
             $pass = $pass && $part['href'] === $url && $part['text'] === SafeMarkup::checkPlain($title);
         }
     }
     // No parts must be left, or an expected "Home" will always pass.
     $pass = $pass && empty($parts);
     $this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', array('%parts' => implode(' » ', $trail), '@path' => $this->getUrl())));
 }
 /**
  * Adds some descriptive text to our entity list.
  *
  * @return array
  *   Renderable array.
  */
 public function render()
 {
     $build['description'] = array('#markup' => $this->t("<p>This is a list of the countries currently" . " defined for use on your Drupal site. This country data adheres to" . " the @iso standard for country and zone naming used by payment" . " providers and package couriers.</p>" . "<p>To make a country available for use at checkout or in a user's" . " address book, 'Enable' the country using the widget in the" . " 'Operations' for that country. You may also 'Disable' a country to" . " prevent customers from selecting that country as a billing or" . " shipping address.</p>" . "<p>You may also use the 'Edit' widget in the 'Operations' column to" . " edit a country's name or address format.</p>", ['@iso' => Link::fromTextAndUrl('ISO 3166', Url::fromUri('http://en.wikipedia.org/wiki/ISO_3166'))->toString()]));
     $build += parent::render();
     $build['table']['#empty'] = $this->t('No countries have been configured yet.');
     return $build;
 }
  /**
   * @param $url
   *
   * @see FillPdfLinkManipulatorInterface::parseUrlString()
   *
   * @return \Drupal\Core\Url
   */
  protected function createUrlFromString($url) {
    $url_parts = UrlHelper::parse($url);
    $path = $url_parts['path'];
    $query = $url_parts['query'];

    $link = Url::fromUri($path, ['query' => $query]);
    return $link;
  }
Beispiel #26
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = array();
     foreach ($items as $delta => $item) {
         $elements[$delta] = array('#type' => 'link', '#title' => $item->value, '#url' => Url::fromUri('mailto:' . $item->value));
     }
     return $elements;
 }
 public function pageContent()
 {
     $content = [];
     $content['left'] = ['#type' => 'container', '#attributes' => ['class' => ['colum-left']], 'imagen_desktop' => ['#markup' => '<img src="/' . drupal_get_path("module", "idoctus_brasil_landing") . '/img/img-big-app.png" title="Mobile imagen" class="img-table-desktop" />'], 'imagen_mobile' => ['#markup' => '<img src="/' . drupal_get_path("module", "idoctus_brasil_landing") . '/img/img-small-app.png" title="Mobile imagen" class="mobile" />'], 'botones_mobile' => ['#type' => 'container', '#attributes' => ['class' => ['btn-app-mobile']], 'register' => ['#type' => 'link', '#title' => $this->t('Register'), '#url' => Url::fromUri('https://www.idoctus.com/user/register'), '#attributes' => ['class' => ['btn', 'btn-inverse']]], 'login' => ['#type' => 'link', '#title' => $this->t('Login'), '#url' => Url::fromUri('https://www.idoctus.com/user/login'), '#attributes' => ['class' => ['btn']]]]];
     $content['rigth'] = ['#type' => 'container', '#attributes' => ['class' => ['colum-right']], 'title' => ['#markup' => '<h2>' . t('Conoce la <strong>App médica</strong> de ayuda en consulta de referencia en español') . '</h2>'], 'Adventages' => ['#theme' => 'item_list', '#list-type' => 'ul', '#items' => [t('More than 120.000 doctors.'), t('Resuleve todas tus dudas en consulta, de diagnóstico y prescripción, con una única App médica.'), t('Ahorra más de 120 minutos a la semana e incrementa la seguridad del paciente.')]]];
     $content['bottom'] = ['#type' => 'container', '#attributes' => ['class' => ['ios-android']], 'android' => ['#type' => 'link', '#title' => ['#markup' => '<img src="/' . drupal_get_path("module", "idoctus_brasil_landing") . '/img/android.png" title="' . $this->t('Ir a Google play') . '" alt="Google play" />'], '#url' => Url::fromUri('https://play.google.com/store/apps/details?id=com.edoctores.android.apps.idoctus')], 'apple' => ['#type' => 'link', '#title' => ['#markup' => '<img src="/' . drupal_get_path("module", "idoctus_brasil_landing") . '/img/ios.png" title="' . $this->t('Ir a iTunes') . '" alt="App store" />'], '#url' => Url::fromUri('https://itunes.apple.com/es/app/idoctus/id530457100?mt=8')]];
     return $content;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('mailchimp.settings');
     $mc_api_url = Url::fromUri('http://admin.mailchimp.com/account/api', array('attributes' => array('target' => '_blank')));
     $form['api_key'] = array('#type' => 'textfield', '#title' => t('Mailchimp API Key'), '#required' => TRUE, '#default_value' => $config->get('api_key'), '#description' => t('The API key for your MailChimp account. Get or generate a valid API key at your !apilink.', array('!apilink' => \Drupal::l(t('MailChimp API Dashboard'), $mc_api_url))));
     $form['cron'] = array('#type' => 'checkbox', '#title' => 'Use batch processing.', '#description' => 'Puts all Mailchimp subscription operations into the cron queue. (Includes subscribe, update, and unsubscribe operations.) <i>Note: May cause confusion if caches are cleared, as requested changes will appear to have failed until cron is run.</i>', '#default_value' => $config->get('cron'));
     $form['batch_limit'] = array('#type' => 'select', '#options' => array('1' => '1', '10' => '10', '25' => '25', '50' => '50', '75' => '75', '100' => '100', '250' => '250', '500' => '500', '750' => '750', '1000' => '1000', '2500' => '2500', '5000' => '5000', '7500' => '7500', '10000' => '10000'), '#title' => t('Batch limit'), '#description' => t('Maximum number of entities to process in a single cron run. Mailchimp suggest keeping this at 5000 or below. <i>This value is also used for batch Merge Variable updates on the Fields tab (part of mailchimp_lists).</i>'), '#default_value' => $config->get('batch_limit'));
     return parent::buildForm($form, $form_state);
 }
 /**
  * Tests system #type 'more_link'.
  */
 function testMoreLink()
 {
     $elements = array(array('name' => "#type 'more_link' anchor tag generation without extra classes", 'value' => array('#type' => 'more_link', '#url' => Url::fromUri('https://www.drupal.org')), 'expected' => '//div[@class="more-link"]/a[@href="https://www.drupal.org" and text()="More"]'), array('name' => "#type 'more_link' anchor tag generation with different link text", 'value' => array('#type' => 'more_link', '#url' => Url::fromUri('https://www.drupal.org'), '#title' => 'More Titles'), 'expected' => '//div[@class="more-link"]/a[@href="https://www.drupal.org" and text()="More Titles"]'), array('name' => "#type 'more_link' anchor tag generation with attributes on wrapper", 'value' => array('#type' => 'more_link', '#url' => Url::fromUri('https://www.drupal.org'), '#theme_wrappers' => array('container' => array('#attributes' => array('title' => 'description', 'class' => array('more-link', 'drupal', 'test'))))), 'expected' => '//div[@title="description" and contains(@class, "more-link") and contains(@class, "drupal") and contains(@class, "test")]/a[@href="https://www.drupal.org" and text()="More"]'), array('name' => "#type 'more_link' anchor tag with a relative path", 'value' => array('#type' => 'more_link', '#url' => Url::fromRoute('router_test.1')), 'expected' => '//div[@class="more-link"]/a[@href="' . Url::fromRoute('router_test.1')->toString() . '" and text()="More"]'), array('name' => "#type 'more_link' anchor tag with a route", 'value' => array('#type' => 'more_link', '#url' => Url::fromRoute('router_test.1')), 'expected' => '//div[@class="more-link"]/a[@href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" and text()="More"]'), array('name' => "#type 'more_link' anchor tag with an absolute path", 'value' => array('#type' => 'more_link', '#url' => Url::fromRoute('system.admin_content'), '#options' => array('absolute' => TRUE)), 'expected' => '//div[@class="more-link"]/a[@href="' . Url::fromRoute('system.admin_content')->setAbsolute()->toString() . '" and text()="More"]'), array('name' => "#type 'more_link' anchor tag to the front page", 'value' => array('#type' => 'more_link', '#url' => Url::fromRoute('<front>')), 'expected' => '//div[@class="more-link"]/a[@href="' . Url::fromRoute('<front>')->toString() . '" and text()="More"]'));
     foreach ($elements as $element) {
         $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value']));
         $result = $xml->xpath($element['expected']);
         $this->assertTrue($result, '"' . $element['name'] . '" input rendered correctly by drupal_render().');
     }
 }
Beispiel #30
-1
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $config = $this->config('swiftmailer.message');
     $form['#tree'] = TRUE;
     $form['description'] = array('#markup' => '<p>' . t('This page allows you to configure settings which determines how e-mail messages are created.') . '</p>');
     if (swiftmailer_validate_library($config->get('path', SWIFTMAILER_VARIABLE_PATH_DEFAULT))) {
         $form['format'] = array('#type' => 'fieldset', '#title' => t('Message format'), '#description' => t('You can set the default message format which should be applied to e-mail
       messages.'));
         $form['format']['type'] = array('#type' => 'radios', '#options' => array(SWIFTMAILER_FORMAT_PLAIN => t('Plain Text'), SWIFTMAILER_FORMAT_HTML => t('HTML')), '#default_value' => $config->get('format', SWIFTMAILER_VARIABLE_FORMAT_DEFAULT));
         $form['format']['respect'] = array('#type' => 'checkbox', '#title' => t('Respect provided e-mail format.'), '#default_value' => $config->get('respect_format', SWIFTMAILER_VARIABLE_RESPECT_FORMAT_DEFAULT), '#description' => t('The header "Content-Type", if available, will be respected if you enable this setting.
       Settings such as e-mail format ("text/plain" or "text/html") and character set may be provided through this
       header. Unless your site somehow alters e-mails, enabling this setting will result in all e-mails to be sent
       as plain text as this is the content type Drupal by default will apply to all e-mails.'));
         $form['convert'] = array('#type' => 'fieldset', '#title' => t('Plain Text Version'), '#description' => t('An alternative plain text version can be generated based on the HTML version if no plain text version
       has been explicitly set. The plain text version will be used by e-mail clients not capable of displaying HTML content.'), '#states' => array('visible' => array('input[type=radio][name=format[type]]' => array('value' => SWIFTMAILER_FORMAT_HTML))));
         $form['convert']['mode'] = array('#type' => 'checkbox', '#title' => t('Generate alternative plain text version.'), '#default_value' => $config->get('convert_mode', SWIFTMAILER_VARIABLE_CONVERT_MODE_DEFAULT), '#description' => t('Please refer to !link for more details about how the alternative plain text version will be generated.', array('!link' => \Drupal::l('html2text', Url::fromUri('http://www.chuggnutt.com/html2text')))));
         $form['character_set'] = array('#type' => 'fieldset', '#title' => t('Character Set'), '#description' => '<p>' . t('E-mails need to carry details about the character set which the
       receiving client should use to understand the content of the e-mail.
       The default character set is UTF-8.') . '</p>');
         $form['character_set']['type'] = array('#type' => 'select', '#options' => swiftmailer_get_character_set_options(), '#default_value' => $config->get('character_set', SWIFTMAILER_VARIABLE_CHARACTER_SET_DEFAULT));
     } else {
         $form['message'] = array('#markup' => '<p>' . t('You need to configure the location of the Swift Mailer library. Please visit the !page
       and configure the library to enable the configuration options on this page.', array('!page' => _l(t('library configuration page'), 'admin/config/people/swiftmailer'))) . '</p>');
     }
     return $form;
 }