Example #1
0
 /**
  * Tests the "popular content" block.
  */
 function testPopularContentBlock()
 {
     // Clear the block cache to load the Statistics module's block definitions.
     $this->container->get('plugin.manager.block')->clearCachedDefinitions();
     // Visit a node to have something show up in the block.
     $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->blockingUser->id()));
     $this->drupalGet('node/' . $node->id());
     // Manually calling statistics.php, simulating ajax behavior.
     $nid = $node->id();
     $post = http_build_query(array('nid' => $nid));
     $headers = array('Content-Type' => 'application/x-www-form-urlencoded');
     global $base_url;
     $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
     $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]);
     $client->post($stats_path, array('headers' => $headers, 'body' => $post));
     // Configure and save the block.
     $this->drupalPlaceBlock('statistics_popular_block', array('label' => 'Popular content', 'top_day_num' => 3, 'top_all_num' => 3, 'top_last_num' => 3));
     // Get some page and check if the block is displayed.
     $this->drupalGet('user');
     $this->assertText('Popular content', 'Found the popular content block.');
     $this->assertText("Today's", "Found today's popular content.");
     $this->assertText('All time', 'Found the all time popular content.');
     $this->assertText('Last viewed', 'Found the last viewed popular content.');
     // statistics.module doesn't use node entities, prevent the node language
     // from being added to the options.
     $this->assertRaw(\Drupal::l($node->label(), $node->urlInfo('canonical', ['language' => NULL])), 'Found link to visited node.');
 }
 /**
  * {@inheritdoc}
  */
 public function overview()
 {
     $content = array();
     $content['description'] = array('#markup' => t('This displays a list of all Mailchimp Subscription Fields
     configured on your system, with a row for each unique Instance of that field.
     To edit each field\'s settings, go to the Entity Bundle\'s configuration
     screen and use the Field UI.
     When entities with MailChimp Subscription Fields are updated,
     the Merge Variables configured through Field UI are automatically updated if necessary.
     However, if you have existing subscribers on MailChimp and matching Entities
     on Drupal when you configure your Merge Variables, the existing values
     are not synced automatically, as this could be a slow process.
     You can manually force updates of all existing Merge Values to existing
     MailChimp subscribers for each field configuration using the \'Batch Update\'
     option on this table. The MailChimp Subscription Field is provided by the
     Mailchimp Lists (mailchimp_lists) module.'));
     $content['fields_table'] = array('#type' => 'table', '#header' => array(t('Entity Type'), t('Bundle'), t('Field'), t('Batch Update')), '#empty' => '');
     $field_map = \Drupal::entityManager()->getFieldMap();
     $row_id = 1;
     foreach ($field_map as $entity_type => $fields) {
         foreach ($fields as $field_name => $field_properties) {
             if ($field_properties['type'] == 'mailchimp_lists_subscription') {
                 foreach ($field_properties['bundles'] as $bundle) {
                     $batch_update_url = Url::fromRoute('mailchimp_lists.update_mergevars', array('entity_type' => $entity_type, 'bundle' => $bundle, 'field_name' => $field_name, 'destination' => 'admin/config/services/mailchimp/fields'));
                     $content['fields_table'][$row_id]['entity_type'] = array('#markup' => $entity_type);
                     $content['fields_table'][$row_id]['bundle'] = array('#markup' => $bundle);
                     $content['fields_table'][$row_id]['field'] = array('#markup' => $field_name);
                     $content['fields_table'][$row_id]['batch_update'] = array('#markup' => \Drupal::l(t('Update Mailchimp Mergevar Values'), $batch_update_url));
                     $row_id++;
                 }
             }
         }
     }
     return $content;
 }
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\oauth2_server\Entity\ClientEntity */
     $row['id'] = $entity->id();
     $row['server'] = \Drupal::l($this->getLabel($entity), new Url('entity.oauth2_server_client.edit_form', array('oauth2_server_client' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var $entity SearchApiPage */
     $row['label'] = $entity->label();
     $row['path'] = \Drupal::l($entity->getPath(), Url::fromRoute('search_api_page.' . $entity->id()));
     return $row + parent::buildRow($entity);
 }
 /**
  * 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' => \Drupal::l('ISO 3166', Url::fromUri('http://en.wikipedia.org/wiki/ISO_3166'))]));
     $build += parent::render();
     $build['table']['#empty'] = $this->t('No countries have been configured yet.');
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\brand\Entity\brand */
     $row['id'] = $entity->id();
     $row['name'] = \Drupal::l($this->getLabel($entity), new Url('entity.brand.edit_form', array('brand' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\eck\Entity\EckEntity */
     $row['id'] = $entity->id();
     $row['title'] = \Drupal::l($this->getLabel($entity), Url::fromRoute('entity.' . $this->entityTypeId . '.canonical', array($this->entityTypeId => $entity->id())));
     return array_merge($row, parent::buildRow($entity));
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $url = Url::fromRoute('autofloat.settings');
     $config_link = \Drupal::l(t('AutoFloat Filter Settings'), $url);
     $form['notice'] = array('#markup' => t('!config_link are shared by all the text formats where it is enabled.', array('!config_link' => $config_link)));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\my_first_entity\Entity\Course */
     $row['id'] = $entity->id();
     $row['name'] = \Drupal::l($this->getLabel($entity), new Url('entity.course.edit_form', array('course' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
 /**
  * {@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);
 }
Example #12
0
 /**
  * Tests the integration.
  */
 public function testIntegration()
 {
     // Remove the watchdog entries added by the potential batch process.
     $this->container->get('database')->truncate('watchdog')->execute();
     $entries = array();
     // Setup a watchdog entry without tokens.
     $entries[] = array('message' => $this->randomMachineName(), 'variables' => array('link' => \Drupal::l('Link', new Url('<front>'))));
     // Setup a watchdog entry with one token.
     $entries[] = array('message' => '@token1', 'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', new Url('<front>'))));
     // Setup a watchdog entry with two tokens.
     $entries[] = array('message' => '@token1 !token2', 'variables' => array('@token1' => $this->randomMachineName(), '!token2' => $this->randomMachineName(), 'link' => \Drupal::l(SafeMarkup::set('<object>Link</object>'), new Url('<front>'))));
     $logger_factory = $this->container->get('logger.factory');
     foreach ($entries as $entry) {
         $entry += array('type' => 'test-views', 'severity' => RfcLogLevel::NOTICE);
         $logger_factory->get($entry['type'])->log($entry['severity'], $entry['message'], $entry['variables']);
     }
     $view = Views::getView('test_dblog');
     $this->executeView($view);
     $view->initStyle();
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), SafeMarkup::format($entry['message'], $entry['variables']));
         $this->assertEqual($view->style_plugin->getField($index, 'link'), Xss::filterAdmin($entry['variables']['link']));
     }
     // Disable replacing variables and check that the tokens aren't replaced.
     $view->destroy();
     $view->storage->invalidateCaches();
     $view->initHandlers();
     $this->executeView($view);
     $view->initStyle();
     $view->field['message']->options['replace_variables'] = FALSE;
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), $entry['message']);
     }
 }
 /**
  * Render a list of entries in the database.
  */
 public function listOfMembers($grouping)
 {
     $content = array();
     $content['add_existing_member'] = $this->formBuilder()->getForm('\\Drupal\\ea_grouping_members\\EAGroupingMembersAddForm', $grouping);
     $content['add_new_member'] = $this->formBuilder()->getForm('\\Drupal\\ea_people\\EAPeopleAddForm');
     $content['message'] = array('#markup' => $this->t('Generate a list of all members of the grouping.'));
     $header = array(array('data' => $this->t('Nickname'), 'field' => 'person.nickname'), array('data' => $this->t('First name'), 'field' => 'person.firstname'), array('data' => $this->t('Last names'), 'field' => 'person.lastnames'), $this->t('Edit'), $this->t('Membership'));
     // Only show members of this grouping.
     $filter = array('gid' => $grouping->gid);
     // Construct table rows.
     $rows = array();
     foreach ($entries = EAGroupingMembersStorage::loadSorted($header, $filter) as $member) {
         // Construct rows.
         $row = array();
         $row['data']['nickname'] = $member->nickname;
         $row['data']['firstname'] = $member->firstname;
         $row['data']['lastnames'] = $member->lastnames;
         // Format edit link.
         $edit_link_url = Url::fromRoute('ea_grouping_members.edit', array('grouping' => $grouping->gid, 'member' => $member->gmid));
         $edit_link = \Drupal::l($this->t('Edit'), $edit_link_url);
         $row['data']['edit_link'] = $edit_link;
         // Format cancel link.
         $cancel_link_url = Url::fromRoute('ea_grouping_members.cancel', array('grouping' => $grouping->gid, 'member' => $member->gmid));
         $cancel_link = \Drupal::l($this->t('Cancel'), $cancel_link_url);
         $row['data']['cancel_link'] = $cancel_link;
         // Add data to row.
         $rows[] = $row;
     }
     $content['table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => t('No members added yet.'));
     $content['pager'] = array('#type' => 'pager');
     return $content;
 }
 /**
  * {@inheritdoc}
  *
  * TODO: Use $langcode.
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getFieldSettings();
     $count = 0;
     // TODO: Is there a better way to get an accurate count of the
     // items from the FieldItemList that doesn't count blank items?
     // Possibly \Countable->count()?
     $storage = \Drupal::entityTypeManager()->getStorage('field_collection_item');
     foreach ($items as $delta => $item) {
         if ($item->value !== NULL) {
             $count++;
             $field_collection_item = $storage->loadRevision($item->revision_id);
             if ($field_collection_item->isDefaultRevision()) {
                 $links = \Drupal::l($this->fieldDefinition->getName() . ' ' . $delta, Url::FromRoute('entity.field_collection_item.canonical', array('field_collection_item' => $item->value)));
                 $links .= ' ' . $this->getEditLinks($item);
             } else {
                 $links = \Drupal::l($this->fieldDefinition->getName() . ' ' . $delta, Url::FromRoute('field_collection_item.revision_show', ['field_collection_item' => $item->value, 'field_collection_item_revision' => $item->revision_id]));
             }
             $element[$delta] = array('#markup' => $links);
         }
     }
     $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
     if ($cardinality == -1 || $count < $cardinality) {
         $element['#suffix'] = '<ul class="action-links action-links-field-collection-add"><li>';
         $element['#suffix'] .= $this->getAddLink($items->getEntity());
         $element['#suffix'] .= '</li></ul>';
     }
     return $element;
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $settings = $this->getConfiguration();
     if (!empty($settings)) {
         /** @var EntityInterface $entity */
         $entity = $this->entity();
         // Basic route parameters
         $route_parameters = array('entityType' => $entity->getEntityTypeId(), 'entityId' => $entity->id());
         $selector = $this->viewMode() == 'default' ? 'full' : $this->viewMode();
         // Basic route options
         $route_options = array('query' => array('selector' => 'view-mode-' . $selector), 'attributes' => array('class' => array('use-ajax')));
         foreach ($settings['vms'] as $key => $value) {
             // If the label is empty, do not create a link
             if (!empty($value)) {
                 $route_parameters['viewMode'] = $key == 'default' ? 'full' : $key;
                 $items[] = \Drupal::l($value, Url::fromRoute('ds_extras.switch_view_mode', $route_parameters, $route_options));
             }
         }
     }
     $output = array();
     if (!empty($items)) {
         $output = array('#theme' => 'item_list', '#items' => $items, '#attached' => array('library' => array('core/drupal.ajax')));
     }
     return $output;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data)
 {
     $element = array();
     $settings = $this->getFieldDefinition()->getFieldStorageDefinition()->getSettings();
     $languages = $this->getPossibleOptions();
     $url = \Drupal::moduleHandler()->moduleExists('language') ? \Drupal::l(t('Languages'), Url::fromRoute('entity.configurable_language.collection')) : '';
     $element['language_range'] = ['#type' => 'checkboxes', '#title' => t('Enabled languages'), '#description' => t("Installed languages can be maintained on the :url\n        page, when Language module is installed. Options marked with '*' are\n        typically used as default value in a hidden widget.", array(':url' => $url)), '#required' => TRUE, '#default_value' => $settings['language_range'], '#options' => array(self::LANGUAGEFIELD_LANGUAGES_PREDEFINED => t('All predefined languages'), LanguageInterface::STATE_CONFIGURABLE => t('All configurable languages'), LanguageInterface::STATE_LOCKED => t('All locked languages'), LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (@language)", array('@language' => \Drupal::languageManager()->getDefaultLanguage()->getName())) . '*', 'current_interface' => t('Current interface language') . '*', 'authors_default' => t("Author's preferred language") . '*')];
     $element['included_languages'] = array('#type' => 'select', '#title' => t('Restrict by language'), '#default_value' => $settings['included_languages'], '#options' => array('' => t('- None -')) + $languages, '#description' => t('If no languages are selected, this filter will not be used.'), '#multiple' => TRUE, '#size' => 10);
     $element['excluded_languages'] = array('#type' => 'select', '#title' => t('Excluded languages'), '#default_value' => $settings['excluded_languages'], '#options' => array('' => t('- None -')) + $languages, '#description' => t('This removes individual languages from the list.'), '#multiple' => TRUE, '#size' => 10);
     $element['groups'] = array('#type' => 'textarea', '#title' => t('Language groups'), '#default_value' => $settings['groups'], '#description' => t("Provides a simple way to group common languages. If no groups are provided, no groupings will be used. Enter in the following format:<br/><code>cn,en,ep,ru<br/>African languages|bs,br<br/>Asian languages|cn,km,fil,ja</code>"), '#multiple' => TRUE, '#size' => 10);
     /*
        $element['groups_help'] = array(
          '#type' => 'fieldset',
          '#title' => t('Group help'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
     
        $items = array();
        foreach ($this->_languagefield_options() as $language) {
          $items[] = t('<strong>@key</strong>: %title', array('@key' => $language['langcode'], '%title' => $language['name']));
        }
        $element['groups_help']['keys'] = array(
          '#type' => 'item',
          '#title' => t('Full language / key listing'),
          '#markup' => theme('item_list', array('items' => $items)),
        );
        $element['groups_help']['all'] = array(
          '#type' => 'item',
          '#title' => t('Available keys'),
          '#markup' => implode(',', array_keys($this->_languagefield_options())),
        );
     */
     return $element;
 }
Example #17
0
 /**
  * Pre-render callback: Renders a link into #markup.
  *
  * Doing so during pre_render gives modules a chance to alter the link parts.
  *
  * @param array $element
  *   A structured array whose keys form the arguments to _l():
  *   - #title: The link text to pass as argument to _l().
  *   - #url: The URL info either pointing to a route or a non routed path.
  *   - #options: (optional) An array of options to pass to _l() or the link
  *     generator.
  *
  * @return array
  *   The passed-in element containing a rendered link in '#markup'.
  */
 public static function preRenderLink($element)
 {
     // By default, link options to pass to _l() are normally set in #options.
     $element += array('#options' => array());
     // However, within the scope of renderable elements, #attributes is a valid
     // way to specify attributes, too. Take them into account, but do not override
     // attributes from #options.
     if (isset($element['#attributes'])) {
         $element['#options'] += array('attributes' => array());
         $element['#options']['attributes'] += $element['#attributes'];
     }
     // This #pre_render callback can be invoked from inside or outside of a Form
     // API context, and depending on that, a HTML ID may be already set in
     // different locations. #options should have precedence over Form API's #id.
     // #attributes have been taken over into #options above already.
     if (isset($element['#options']['attributes']['id'])) {
         $element['#id'] = $element['#options']['attributes']['id'];
     } elseif (isset($element['#id'])) {
         $element['#options']['attributes']['id'] = $element['#id'];
     }
     // Conditionally invoke self::preRenderAjaxForm(), if #ajax is set.
     if (isset($element['#ajax']) && !isset($element['#ajax_processed'])) {
         // If no HTML ID was found above, automatically create one.
         if (!isset($element['#id'])) {
             $element['#id'] = $element['#options']['attributes']['id'] = HtmlUtility::getUniqueId('ajax-link');
         }
         $element = static::preRenderAjaxForm($element);
     }
     if (!empty($element['#url'])) {
         $options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']);
         $element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options));
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $fblikebutton_node_options = node_type_get_names();
     $config = $this->config('fblikebutton.settings');
     $form['fblikebutton_dynamic_visibility'] = array('#type' => 'details', '#title' => $this->t('Visibility settings'), '#open' => TRUE);
     $form['fblikebutton_dynamic_visibility']['fblikebutton_node_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Display the Like button on these content types:'), '#options' => $fblikebutton_node_options, '#default_value' => $config->get('node_types'), '#description' => $this->t('Each of these content types will have the "like" button automatically added to them.'));
     /** 
      * @TODO: Uncomment this when the module is also able to add the button to 
      * the links area
      * 
     $form['fblikebutton_dynamic_visibility']['fblikebutton_full_node_display'] = array(
       '#type' => 'radios',
       '#title' => $this->t('Where do you want to show the Like button (full node view)?'),
       '#options' => array(
         $this->t('Content area'),
         $this->t('Links area')
       ),
       '#default_value' => $config->get('full_node_display'),
       '#description' => $this->t('If <em>Content area</em> is selected, the button will appear in the same area as the node content. When you select <em>Links area</em> the Like button will be visible in the links area, usually at the bottom of the node (When you select this last option you may want to adjust the Appearance settings). You can also configure Static Like Button Blocks in'. \Drupal::l($this->t('block page'), Url::fromRoute('block.admin_display')) . '.'),
     );
     */
     $form['fblikebutton_dynamic_visibility']['fblikebutton_teaser_display'] = array('#type' => 'radios', '#title' => $this->t('Where do you want to show the Like button on teasers?'), '#options' => array($this->t('Don\'t show on teasers'), $this->t('Content area')), '#default_value' => $config->get('teaser_display'), '#description' => $this->t('If you want to show the like button on teasers you can select the display area.'));
     $form['fblikebutton_dynamic_appearance'] = array('#type' => 'details', '#title' => $this->t('Appearance settings'), '#open' => TRUE);
     $form['fblikebutton_dynamic_appearance']['fblikebutton_layout'] = array('#type' => 'select', '#title' => $this->t('Layout style'), '#options' => array('standard' => $this->t('Standard'), 'box_count' => $this->t('Box Count'), 'button_count' => $this->t('Button Count'), 'button' => $this->t('Button')), '#default_value' => $config->get('layout'), '#description' => $this->t('Determines the size and amount of social context next to the button.'));
     // The actial values passed in from the options will be converted to a boolean
     // in the validation function, so it doesn't really matter what we use.
     $form['fblikebutton_dynamic_appearance']['fblikebutton_show_faces'] = array('#type' => 'select', '#title' => $this->t('Show faces in the box?'), '#options' => array(t('Do not show faces'), $this->t('Show faces')), '#default_value' => $config->get('show_faces', TRUE), '#description' => $this->t('Show profile pictures below the button. Only works if <em>Layout style</em> (found above) is set to <em>Standard</em> (otherwise, value is ignored).'));
     $form['fblikebutton_dynamic_appearance']['fblikebutton_action'] = array('#type' => 'select', '#title' => $this->t('Verb to display'), '#options' => array('like' => $this->t('Like'), 'recommend' => $this->t('Recommend')), '#default_value' => $config->get('action'), '#description' => $this->t('The verbiage to display inside the button itself.'));
     $form['fblikebutton_dynamic_appearance']['fblikebutton_font'] = array('#type' => 'select', '#title' => $this->t('Font'), '#options' => array('arial' => 'Arial', 'lucida+grande' => 'Lucida Grande', 'segoe+ui' => 'Segoe UI', 'tahoma' => 'Tahoma', 'trebuchet+ms' => 'Trebuchet MS', 'verdana' => 'Verdana'), '#default_value' => $config->get('font', 'arial'), '#description' => $this->t('The font with which to display the text of the button.'));
     $form['fblikebutton_dynamic_appearance']['fblikebutton_color_scheme'] = array('#type' => 'select', '#title' => $this->t('Color scheme'), '#options' => array('light' => $this->t('Light'), 'dark' => $this->t('Dark')), '#default_value' => $config->get('color_scheme'), '#description' => $this->t('The color scheme of the box environtment.'));
     $form['fblikebutton_dynamic_appearance']['fblikebutton_weight'] = array('#type' => 'number', '#title' => $this->t('Weight'), '#default_value' => $config->get('weight'), '#description' => $this->t('The weight determines where, at the content block, the like button will appear. The larger the weight, the lower it will appear on the node. For example, if you want the button to appear more toward the top of the node, choose <em>-40</em> as opposed to <em>-39, -38, 0, 1,</em> or <em>50,</em> etc. To position the Like button in its own block, go to the ' . \Drupal::l($this->t('block page'), Url::fromRoute('block.admin_display')) . '.'));
     $form['fblikebutton_dynamic_appearance']['fblikebutton_language'] = array('#type' => 'textfield', '#title' => $this->t('Language'), '#default_value' => $config->get('language'), '#description' => $this->t('Specific language to use. Default is English. Examples:<br />French (France): <em>fr_FR</em><br />French (Canada): <em>fr_CA</em><br />More information can be found at http://developers.facebook.com/docs/internationalization/ and a full XML list can be found at http://www.facebook.com/translations/FacebookLocales.xml'));
     return parent::buildForm($form, $form_state);
 }
 /**
  * Create an overview of webform content.
  */
 public function contentOverview()
 {
     // @todo This needs to be removed and the view webform_webforms used instead.
     $query = db_select('webform', 'w');
     $query->join('node', 'n', 'w.nid = n.nid');
     $query->fields('n');
     $nodes = $query->execute()->fetchAllAssoc('nid');
     module_load_include('inc', 'webform', 'includes/webform.admin');
     $header = array(t('Title'), array('data' => t('View'), 'colspan' => '4'), array('data' => t('Operations'), 'colspan' => '3'));
     $rows = array();
     if (!empty($nodes)) {
         foreach ($nodes as $node) {
             $node = Node::load($node->nid);
             $rows[] = array(\Drupal::l($node->getTitle(), Url::fromRoute('entity.node.canonical', ['node' => $node->id()])), t('Submissions'), t('Analysis'), t('Table'), t('Download'), $node->access('update') ? \Drupal::l(t('Edit'), Url::fromRoute('entity.node.edit_form', ['node' => $node->id()])) : '', t('Components'), t('Clear'));
         }
     }
     if (empty($nodes)) {
         $webform_types = webform_node_types();
         if (empty($webform_types)) {
             $message = t('Webform is currently not enabled on any content types.') . ' ' . t('Visit the <a href="!url">Webform settings</a> page and enable Webform on at least one content type.', array('!url' => Url::fromRoute('webform.settings')->toString()));
         } else {
             $webform_type_list = webform_admin_type_list();
             $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list));
         }
         $rows[] = array(array('data' => $message, 'colspan' => 7));
     }
     $table = array('#type' => 'table', '#header' => $header, '#rows' => $rows);
     return $table;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\interns\Entity\InternsEntity */
     $row['id'] = $entity->id();
     $row['name'] = \Drupal::l($this->getLabel($entity), new Url('entity.interns_entity.edit_form', array('interns_entity' => $entity->id())));
     $row['interns'] = $entity->interns->value;
     return $row + parent::buildRow($entity);
 }
 /**
  * Builds an individual term item for the term item list depending on the formatter.
  *
  * @param \Drupal\taxonomy\Entity\Term $term
  * @return string
  */
 private function buildTermListItem(Term $term, $formatter)
 {
     if ($formatter === 'linked') {
         $link_url = Url::fromRoute('entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id()));
         return \Drupal::l($term->label(), $link_url);
     }
     return HTML::escape($term->label());
 }
 function testViewsHandlerTidField()
 {
     $view = Views::getView('test_taxonomy_tid_field');
     $this->executeView($view);
     $actual = $view->field['name']->advancedRender($view->result[0]);
     $expected = \Drupal::l($this->term1->label(), $this->term1->urlInfo());
     $this->assertEqual($expected, $actual);
 }
 /**
  * Constructs a page with a descriptive content.
  *
  * Our router maps this method to the path 'examples/page_example'.
  */
 public function description()
 {
     $simple_url = Url::fromRoute('page_example_simple');
     $simple_link = \Drupal::l(t('simple page'), $simple_url);
     $arguments_url = Url::fromRoute('page_example_description', [], ['absolute' => TRUE]);
     $arguments_link = \Drupal::l(t('arguments page'), $arguments_url);
     $build = ['#markup' => t('<p>The Page example module provides two pages, "simple" and "arguments".</p>' . '<p>The !simple_link just returns a renderable array for display.</p>' . '<p>The !arguments_link takes two arguments and displays them, as in @arguments_url</p>', ['!simple_link' => $simple_link, '!arguments_link' => $arguments_link, '@arguments_url' => $arguments_url->toString()])];
     return $build;
 }
 /**
  * {@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);
 }
Example #25
0
 /**
  * A simple controller method to explain what the block example is about.
  */
 public function description()
 {
     // Make a link from a route to the block admin page.
     $url = Url::fromRoute('block.admin_display');
     $block_admin_link = \Drupal::l(t('the block admin page'), $url);
     // Put the link into the content.
     $build = array('#markup' => t('The Block Example provides three sample blocks which demonstrate the various block APIs. To experiment with the blocks, enable and configure them on !block_admin_link.', array('!block_admin_link' => $block_admin_link)));
     return $build;
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $destination = drupal_get_destination();
     $search = $this->getRequest()->get('search');
     $form['#attributes'] = array('class' => array('search-form'));
     // The following requires the dblog module. If it's not available, provide a message.
     if (!\Drupal::moduleHandler()->moduleExists('dblog')) {
         $form['message'] = ['#type' => 'markup', '#markup' => t('This page requires the Database Logging (dblog) module, which is currently not installed.')];
         return $form;
     }
     $form['basic'] = array('#type' => 'fieldset', '#title' => t('Filter 404s'), '#attributes' => array('class' => array('container-inline')));
     $form['basic']['filter'] = array('#type' => 'textfield', '#title' => '', '#default_value' => $search, '#maxlength' => 128, '#size' => 25);
     $form['basic']['submit'] = array('#type' => 'submit', '#value' => t('Filter'), '#action' => 'filter');
     if ($search) {
         $form['basic']['reset'] = array('#type' => 'submit', '#value' => t('Reset'), '#action' => 'reset');
     }
     $header = array(array('data' => t('Page'), 'field' => 'message'), array('data' => t('Count'), 'field' => 'count', 'sort' => 'desc'), array('data' => t('Last accessed'), 'field' => 'timestamp'), array('data' => t('Operations')));
     $count_query = db_select('watchdog', 'w');
     $count_query->addExpression('COUNT(DISTINCT(w.message))');
     $count_query->leftJoin('redirect', 'r', 'w.message = r.redirect_source__path');
     $count_query->condition('w.type', 'page not found');
     $count_query->isNull('r.rid');
     $this->filterQuery($count_query, array('w.message'), $search);
     $query = db_select('watchdog', 'w')->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')->orderByHeader($header)->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')->limit(25);
     $query->fields('w', array('message', 'variables'));
     $query->addExpression('COUNT(wid)', 'count');
     $query->addExpression('MAX(timestamp)', 'timestamp');
     $query->leftJoin('redirect', 'r', 'w.message = r.redirect_source__path');
     $query->isNull('r.rid');
     $query->condition('w.type', 'page not found');
     $query->groupBy('w.message');
     $query->groupBy('w.variables');
     $this->filterQuery($query, array('w.message'), $search);
     $query->setCountQuery($count_query);
     $results = $query->execute();
     $rows = array();
     foreach ($results as $result) {
         // @todo Detect the language from the url.
         $url = SafeMarkup::format($result->message, unserialize($result->variables));
         $request = Request::create($url, 'GET', [], [], [], \Drupal::request()->server->all());
         $path = ltrim($request->getPathInfo(), '/');
         $row = array();
         $row['source'] = \Drupal::l($url, Url::fromUri('base:' . $path, array('query' => $destination)));
         $row['count'] = $result->count;
         $row['timestamp'] = format_date($result->timestamp, 'short');
         $operations = array();
         if (\Drupal::entityManager()->getAccessControlHandler('redirect')->createAccess()) {
             $operations['add'] = array('title' => t('Add redirect'), 'url' => Url::fromRoute('redirect.add', [], ['query' => array('source' => $path) + $destination]));
         }
         $row['operations'] = array('data' => array('#theme' => 'links', '#links' => $operations, '#attributes' => array('class' => array('links', 'inline', 'nowrap'))));
         $rows[] = $row;
     }
     $form['redirect_404_table'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => t('No 404 pages without redirects found.'));
     $form['redirect_404_pager'] = array('#type' => 'pager');
     return $form;
 }
 protected function getAddLink(ContentEntityInterface $host)
 {
     $link = '';
     if ($host->access('update', \Drupal::currentUser())) {
         $link = '<ul class="action-links action-links-field-collection-add"><li>';
         $link .= \Drupal::l(t('Add'), Url::FromRoute('field_collection_item.add_page', ['field_collection' => $this->fieldDefinition->getName(), 'host_type' => $host->getEntityTypeId(), 'host_id' => $host->id()]));
         $link .= '</li></ul>';
     }
     return $link;
 }
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = [];
     $build['tweets_block']['#markup'] = $this->tweets;
     $config = \Drupal::config('tweets.settings');
     $username = '******' . $config->get('twitter_username') . '">@' . $config->get('twitter_username') . '</a>';
     $tweets = array_slice($this->tweets, 0, 3);
     $more = \Drupal::l(t('More tweets'), Url::fromRoute('tweets.content'));
     return array('#theme' => 'tweets_block', '#username' => $username, '#tweets' => $tweets, '#more' => $more, '#attached' => array('library' => array('tweets/base')));
 }
Example #29
-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;
 }
Example #30
-2
 protected function setUp()
 {
     parent::setUp();
     // Create Basic page node type.
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('page' => 'page'), 'weight' => mt_rand(0, 10)));
     $vocabulary->save();
     // Create a field.
     $field_name = Unicode::strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'page', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     // Create a time in the past for the archive.
     $time = REQUEST_TIME - 3600;
     $this->addDefaultCommentField('node', 'page');
     for ($i = 0; $i <= 10; $i++) {
         $user = $this->drupalCreateUser();
         $term = $this->createTerm($vocabulary);
         $values = array('created' => $time, 'type' => 'page');
         $values[$field_name][]['target_id'] = $term->id();
         // Make every other node promoted.
         if ($i % 2) {
             $values['promote'] = TRUE;
         }
         $values['body'][]['value'] = \Drupal::l('Node ' . 1, new Url('entity.node.canonical', ['node' => 1]));
         $node = $this->drupalCreateNode($values);
         $comment = array('uid' => $user->id(), 'status' => CommentInterface::PUBLISHED, 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment');
         entity_create('comment', $comment)->save();
     }
     // Some views, such as the "Who's Online" view, only return results if at
     // least one user is logged in.
     $account = $this->drupalCreateUser(array());
     $this->drupalLogin($account);
 }