/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['id'] = $entity->id();
     // Render encryption method row.
     if ($encryption_method = $entity->getEncryptionMethod()) {
         $row['encryption_method'] = $encryption_method->getLabel();
     } else {
         $row['encryption_method'] = $this->t('Error loading encryption method');
     }
     // Render encryption key row.
     if ($key = $entity->getEncryptionKey()) {
         $row['key'] = $key->label();
     } else {
         $row['key'] = $this->t('Error loading key');
     }
     // Render status report row.
     if ($this->config->get('check_profile_status')) {
         $errors = $entity->validate();
         if (!empty($errors)) {
             $row['status']['data'] = array('#theme' => 'item_list', '#items' => $errors, '#attributes' => array("class" => array("color-error")));
         } else {
             $row['status'] = $this->t('OK');
         }
     }
     return $row + parent::buildRow($entity);
 }
 /**
  * Instances a new dumper plugin.
  *
  * @param string $plugin_id
  *   (optional) The plugin ID, defaults to NULL.
  *
  * @return \Drupal\devel\DevelDumperInterface
  *   Returns the devel dumper plugin instance.
  */
 protected function createInstance($plugin_id = NULL)
 {
     if (!$plugin_id || !$this->dumperManager->isPluginSupported($plugin_id)) {
         $plugin_id = $this->config->get('devel_dumper');
     }
     return $this->dumperManager->createInstance($plugin_id);
 }
 /**
  * Gets a redirect for given path, query and language.
  *
  * @param string $source_path
  *   The redirect source path.
  * @param array $query
  *   The redirect source path query.
  * @param $language
  *   The language for which is the redirect.
  *
  * @return \Drupal\redirect\Entity\Redirect
  *   The matched redirect entity.
  *
  * @throws \Drupal\redirect\Exception\RedirectLoopException
  */
 public function findMatchingRedirect($source_path, array $query = [], $language = Language::LANGCODE_NOT_SPECIFIED)
 {
     $hashes = [Redirect::generateHash($source_path, $query, $language)];
     if ($language != Language::LANGCODE_NOT_SPECIFIED) {
         $hashes[] = Redirect::generateHash($source_path, $query, Language::LANGCODE_NOT_SPECIFIED);
     }
     // Add a hash without the query string if using passthrough querystrings.
     if (!empty($query) && $this->config->get('passthrough_querystring')) {
         $hashes[] = Redirect::generateHash($source_path, [], $language);
         if ($language != Language::LANGCODE_NOT_SPECIFIED) {
             $hashes[] = Redirect::generateHash($source_path, [], Language::LANGCODE_NOT_SPECIFIED);
         }
     }
     // Load redirects by hash. A direct query is used to improve performance.
     $rid = $this->connection->query('SELECT rid FROM {redirect} WHERE hash IN (:hashes[]) ORDER BY LENGTH(redirect_source__query) DESC', [':hashes[]' => $hashes])->fetchField();
     if (!empty($rid)) {
         // Check if this is a loop.
         if (in_array($rid, $this->foundRedirects)) {
             throw new RedirectLoopException('/' . $source_path, $rid);
         }
         $this->foundRedirects[] = $rid;
         $redirect = $this->load($rid);
         // Find chained redirects.
         if ($recursive = $this->findByRedirect($redirect, $language)) {
             // Reset found redirects.
             $this->foundRedirects = [];
             return $recursive;
         }
         return $redirect;
     }
     return NULL;
 }
 /**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = [])
 {
     $this->logs[] = ['level' => $level, 'message' => $message, 'context' => $context];
     // Log message only if rules logging setting is enabled.
     if ($this->config->get('debug_log')) {
         if ($this->levelTranslation[$this->config->get('log_errors')] >= $this->levelTranslation[$level]) {
             parent::log($level, $message, $context);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $this->getLabel($entity);
     $row['id'] = $entity->id();
     $row['key'] = $entity->getEncryptionKey();
     if ($this->config->get('check_profile_status')) {
         $errors = $entity->validate();
         if (!empty($errors)) {
             $row['status']['data'] = array('#theme' => 'item_list', '#items' => $errors, '#attributes' => array("class" => array("color-error")));
         } else {
             $row['status'] = $this->t('OK');
         }
     }
     return $row + parent::buildRow($entity);
 }
 /**
  * Determine if the Flippy pager should be shown for the give node.
  *
  * @param $node
  *   Node to check for pager
  *
  * @return bool Boolean: TRUE if pager should be shown, FALSE if not
  */
 public function flippy_use_pager($node)
 {
     if (!is_object($node)) {
         return FALSE;
     }
     return node_is_page($node) && $this->flippySettings->get('flippy_' . $node->getType());
 }
 /**
  * {@inheritdoc}
  */
 public function getChangesList(SubscriberInterface $subscriber, $changes = NULL, $langcode = NULL)
 {
     if (empty($langcode)) {
         $language = $this->languageManager->getCurrentLanguage();
         $langcode = $language->getId();
     }
     if (empty($changes)) {
         $changes = $subscriber->getChanges();
     }
     $changes_list = array();
     foreach ($changes as $newsletter_id => $action) {
         $subscribed = $subscriber->isSubscribed($newsletter_id);
         // Get text for each possible combination.
         if ($action == 'subscribe' && !$subscribed) {
             $line = $this->config->get('subscription.confirm_combined_line_subscribe_unsubscribed');
         } elseif ($action == 'subscribe' && $subscribed) {
             $line = $this->config->get('subscription.confirm_combined_line_subscribe_subscribed');
         } elseif ($action == 'unsubscribe' && !$subscribed) {
             $line = $this->config->get('subscription.confirm_combined_line_unsubscribe_unsubscribed');
         } elseif ($action == 'unsubscribe' && $subscribed) {
             $line = $this->config->get('subscription.confirm_combined_line_unsubscribe_subscribed');
         }
         $newsletter_context = array('simplenews_subscriber' => $subscriber, 'newsletter' => simplenews_newsletter_load($newsletter_id));
         $changes_list[$newsletter_id] = $this->token->replace($line, $newsletter_context, array('sanitize' => FALSE));
     }
     return $changes_list;
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $output = NULL;
     static $running = [];
     // Protect against the evil / recursion.
     // Set the variable for yourself, this is not for the normal "user".
     if (empty($running[$this->options['view']][$this->options['display']]) || $this->config->get('evil')) {
         if (!empty($this->options['view'])) {
             $running[$this->options['view']][$this->options['display']] = TRUE;
             $args = [];
             // Only perform this loop if there are actually arguments present.
             if (!empty($this->options['arguments'])) {
                 // Create array of tokens.
                 foreach ($this->splitTokens($this->options['arguments']) as $token) {
                     $args[] = $this->getTokenValue($token, $values, $this->view);
                 }
             }
             // Get view and execute.
             $view = Views::getView($this->options['view']);
             // Only execute and render the view if the user has access.
             if ($view->access($this->options['display'])) {
                 $view->setDisplay($this->options['display']);
                 if ($view->display_handler->isPagerEnabled()) {
                     // Check whether the pager IDs should be rewritten.
                     $view->initQuery();
                     // Find a proper start value for the ascening pager IDs.
                     $start = 0;
                     $pager = $view->display_handler->getOption('pager');
                     if (isset($this->query->pager->options['id'])) {
                         $start = (int) $this->query->pager->options['id'];
                     }
                     // Set the pager ID before initializing the pager, so
                     // views_plugin_pager::set_current_page works as expected, which is
                     // called from view::init_pager()
                     $pager['options']['id'] = $start + 1 + $this->view->row_index;
                     $view->display_handler->setOption('pager', $pager);
                     $view->initPager();
                 }
                 $view->preExecute($args);
                 $view->execute();
                 // If there are no results and hide_empty is set.
                 if (empty($view->result) && $this->options['hide_empty']) {
                     $output = '';
                 } else {
                     $output = $view->render();
                 }
             }
             $running[$this->options['view']][$this->options['display']] = FALSE;
         }
     } else {
         $output = $this->t('Recursion, stop!');
     }
     if (!empty($output)) {
         // Add the rendered output back to the $values object
         // so it is available in $view->result objects.
         $values->{'views_field_view_' . $this->options['id']} = $output;
     }
     return $output;
 }
 /**
  * {@inheritdoc}
  */
 public function getFrom()
 {
     $address = $this->config->get('newsletter.from_address');
     $name = $this->config->get('newsletter.from_name');
     // Windows based PHP systems don't accept formatted email addresses.
     $formatted_address = Unicode::substr(PHP_OS, 0, 3) == 'WIN' ? $address : '"' . addslashes(Unicode::mimeHeaderEncode($name)) . '" <' . $address . '>';
     return array('address' => $address, 'formatted' => $formatted_address);
 }
Exemple #10
0
 /**
  * Adds a lightbox to a link.
  *
  * @param array $link
  *   The link we want to add the lightbox to.
  */
 public function addLightbox(array &$link)
 {
     // Safety check if class isn't an array.
     if (!isset($link['options']['attributes']['class'])) {
         $link['options']['attributes']['class'] = array();
     }
     // Add our lightbox class.
     $link['options']['attributes']['class'][] = 'use-ajax';
     $link['options']['attributes']['data-dialog-type'] = str_replace('drupal_', '', $this->config->get('renderer') ?: static::DEFAULT_MODAL);
     $data = ['width' => $this->config->get('default_width')];
     $link['options']['attributes']['data-dialog-options'] = json_encode($data);
 }
 /**
  * {@inheritdoc}
  */
 function buildUnsubscribeMail(&$message, $params)
 {
     $context = $params['context'];
     // Use formatted from address "name" <mail_address>
     $message['headers']['From'] = $params['from']['formatted'];
     $message['subject'] = $this->config->get('subscription.confirm_subscribe_subject');
     $message['subject'] = $this->token->replace($message['subject'], $context, array('sanitize' => FALSE));
     if ($context['simplenews_subscriber']->isSubscribed($context['newsletter']->id())) {
         $body = $this->config->get('subscription.confirm_unsubscribe_subscribed');
         $message['body'][] = $this->token->replace($body, $context, array('sanitize' => FALSE));
     } else {
         $body = $this->config->get('subscription.confirm_unsubscribe_unsubscribed');
         $message['body'][] = $this->token->replace($body, $context, array('sanitize' => FALSE));
     }
 }
 /**
  * Implements \Drupal\block\BlockBase::build().
  */
 public function build()
 {
     $build = array();
     // Detect if we're viewing a node
     if ($node = $this->request->attributes->get('node')) {
         // Make sure this node type is still enabled
         if ($this->flippyPager->flippy_use_pager($node)) {
             $build = ['#theme' => 'flippy', '#list' => $this->flippyPager->flippy_build_list($node), '#node' => $node, '#attached' => array('library' => array('flippy/drupal.flippy'))];
             // Set head elements
             if (is_object($node)) {
                 if ($this->flippySettings->get('flippy_head_' . $node->getType())) {
                     $links = $this->flippyPager->flippy_build_list($node);
                     if (!empty($links['prev']['nid'])) {
                         $build['#attached']['html_head_link'][][] = array('rel' => 'prev', 'href' => Url::fromRoute('entity.node.canonical', array('node' => $links['prev']['nid']))->toString());
                     }
                     if (!empty($links['next']['nid'])) {
                         $build['#attached']['html_head_link'][][] = array('rel' => 'next', 'href' => Url::fromRoute('entity.node.canonical', array('node' => $links['next']['nid']))->toString());
                     }
                 }
             }
         }
     }
     return $build;
 }
Exemple #13
0
 /**
  * Calculates number of words, which a text consists of.
  *
  * @param string $text
  *
  * @return int $count
  *   Returns count of words of text.
  */
 public function wordCount($text)
 {
     // Strip tags in case it is requested to not include them in the count.
     if ($this->config->get('word_count_exclude_tags')) {
         $text = strip_tags($text);
     }
     // Replace each punctuation mark with space.
     $text = str_replace(array('`', '~', '!', '@', '"', '#', '$', ';', '%', '^', ':', '?', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', '\\', '|', '/', '\'', '<', '>', ',', '.'), ' ', $text);
     // Remove duplicate spaces.
     $text = trim(preg_replace('/ {2,}/', ' ', $text));
     // Turn into an array.
     $array = $text ? explode(' ', $text) : array();
     // How many are they?
     $count = count($array);
     // That is what we need.
     return $count;
 }
  /**
   * Applies the crop effect to an image.
   *
   * @param ImageInterface $image
   *   The image resource to crop.
   *
   * @return bool
   *   TRUE if the image is successfully cropped, otherwise FALSE.
   */
  public function applyCrop(ImageInterface $image) {
    $crop_type = $this->focalPointConfig->get('crop_type');

    /** @var \Drupal\crop\CropInterface $crop */
    if ($crop = Crop::findCrop($image->getSource(), $crop_type)) {
      // An existing crop has been found; set the size.
      $crop->setSize($this->configuration['width'], $this->configuration['height']);
    }
    else {
      // No existing crop could be found; create a new one using the size.
      $crop = $this->cropStorage->create([
        'type' => $crop_type,
        'x' => (int) round($image->getWidth() / 2),
        'y' => (int) round($image->getHeight() / 2),
        'width' => $this->configuration['width'],
        'height' => $this->configuration['height'],
      ]);
    }

    // Get the top-left anchor position of the crop area.
    $anchor = $this->getAnchor($image, $crop);

    if (!$image->crop($anchor['x'], $anchor['y'], $this->configuration['width'], $this->configuration['height'])) {
      $this->logger->error(
        'Focal point scale and crop failed while scaling and cropping using the %toolkit toolkit on %path (%mimetype, %dimensions, anchor: %anchor)',
        [
          '%toolkit' => $image->getToolkitId(),
          '%path' => $image->getSource(),
          '%mimetype' => $image->getMimeType(),
          '%dimensions' => $image->getWidth() . 'x' . $image->getHeight(),
          '%anchor' => $anchor,
        ]
      );
      return FALSE;
    }

    return TRUE;
  }
 /**
  * Returns the expiration time for IN_PROGRESS status.
  *
  * @return int
  *   A unix timestamp. Any IN_PROGRESS messages with a timestamp older than
  *   this will be re-allocated and re-sent.
  */
 protected function getExpirationTime()
 {
     $timeout = $this->config->get('mail.spool_progress_expiration');
     $expiration_time = REQUEST_TIME - $timeout;
     return $expiration_time;
 }
 /**
  * {@inheritdoc}
  */
 public function attach(array &$page)
 {
     if ($this->settings->get('custom.activate')) {
         $js_settings = array('transition' => $this->settings->get('custom.transition_type'), 'speed' => $this->settings->get('custom.transition_speed'), 'opacity' => $this->settings->get('custom.opacity'), 'slideshow' => $this->settings->get('custom.slideshow.slideshow') ? TRUE : FALSE, 'slideshowAuto' => $this->settings->get('custom.slideshow.auto') ? TRUE : FALSE, 'slideshowSpeed' => $this->settings->get('custom.slideshow.speed'), 'slideshowStart' => $this->settings->get('custom.slideshow.text_start'), 'slideshowStop' => $this->settings->get('custom.slideshow.text_stop'), 'current' => $this->settings->get('custom.text_current'), 'previous' => $this->settings->get('custom.text_previous'), 'next' => $this->settings->get('custom.text_next'), 'close' => $this->settings->get('custom.text_close'), 'overlayClose' => $this->settings->get('custom.overlayclose') ? TRUE : FALSE, 'maxWidth' => $this->settings->get('custom.maxwidth'), 'maxHeight' => $this->settings->get('custom.maxheight'), 'initialWidth' => $this->settings->get('custom.initialwidth'), 'initialHeight' => $this->settings->get('custom.initialheight'), 'fixed' => $this->settings->get('custom.fixed') ? TRUE : FALSE, 'scrolling' => $this->settings->get('custom.scrolling') ? TRUE : FALSE, 'mobiledetect' => $this->settings->get('advanced.mobile_detect') ? TRUE : FALSE, 'mobiledevicewidth' => $this->settings->get('advanced.mobile_device_width'));
     } else {
         $js_settings = array('opacity' => '0.85', 'current' => t('{current} of {total}'), 'previous' => t('« Prev'), 'next' => t('Next »'), 'close' => t('Close'), 'maxWidth' => '98%', 'maxHeight' => '98%', 'fixed' => TRUE, 'mobiledetect' => $this->settings->get('advanced.mobile_detect') ? TRUE : FALSE, 'mobiledevicewidth' => $this->settings->get('advanced.mobile_device_width'));
     }
     $style = $this->settings->get('custom.style');
     // Give other modules the possibility to override Colorbox settings and style.
     $this->moduleHandler->alter('colorbox_settings', $js_settings, $style);
     // Add colorbox js settings.
     $page['#attached']['drupalSettings']['colorbox'] = $js_settings;
     // Add and initialise the Colorbox plugin.
     if ($this->settings->get('advanced.compression_type' == 'minified')) {
         $page['#attached']['library'][] = 'colorbox/colorbox';
     } else {
         $page['#attached']['library'][] = 'colorbox/colorbox-dev';
     }
     // Add JS and CSS based on selected style.
     if ($style != 'none') {
         $page['#attached']['library'][] = "colorbox/{$style}";
     }
 }
 /**
  * @covers ::delete
  * @expectedException \Drupal\Core\Config\ImmutableConfigException
  * @expectedExceptionMessage Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object
  */
 public function testDelete()
 {
     $this->config->delete();
 }
 /**
  * Gets query values for Disqus widget URL.
  *
  * @return array
  *   Array of query values for Disqus widget URL.
  */
 protected function buildQuery()
 {
     return ['domain' => $this->disqusConfig->get('disqus_domain'), 'num_items' => $this->configuration['items']];
 }
Exemple #19
0
 /**
  * The controller for the meteor.backlink route.
  *
  * @return array
  *   The render array for the Meteor backlink.
  */
 public function backlink()
 {
     $server_uri = Url::fromUri($this->meteorSettings->get('meteor_server'));
     $ret = Link::fromTextAndUrl("Go to Meteor", $server_uri)->toRenderable();
     return $ret;
 }
 protected function getTimeout() {
   return (int)$this->config->get('timeout')? $this->config->get('timeout') : 15;
 }