Esempio n. 1
0
 /**
  * Attempts to enable a module with a missing dependency.
  */
 function testMissingModules()
 {
     // Test that the system_dependencies_test module is marked
     // as missing a dependency.
     $this->drupalGet('admin/modules');
     $this->assertRaw(t('@module (<span class="admin-missing">missing</span>)', array('@module' => Unicode::ucfirst('_missing_dependency'))), 'A module with missing dependencies is marked as such.');
     $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[Testing][system_dependencies_test][enable]"]');
     $this->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('acquia_connector.settings');
     $identifier = $config->get('identifier');
     $key = $config->get('key');
     $client = \Drupal::service('acquia_connector.client');
     $error = NULL;
     try {
         $data = $client->nspiCall('/agent-migrate-api/subscription/migration/environments', array('identifier' => $identifier), $key);
     } catch (ConnectorException $e) {
         if ($e->isCustomized()) {
             acquia_connector_report_restapi_error($e->getCustomMessage('code'), $e->getCustomMessage());
             return $this->redirect('acquia_connector.settings');
         }
         $error = $this->t('Server error, please submit again.');
     }
     if (!empty($data['result'])) {
         // Response is in $data['result'].
         $result = $data['result'];
         if (!empty($result['is_error'])) {
             $error = $this->t('Server error, unable to retrieve environments for migration');
         } elseif (!empty($result['body']['error'])) {
             $error = $result['body']['error'];
         } elseif (empty($result['body']['environments'])) {
             $error = $this->t('Server error, unable to retrieve environments for migration');
         }
     }
     if ($error) {
         drupal_set_message($error, 'error');
         return $this->redirect('acquia_connector.settings');
     }
     foreach ($result['body']['environments'] as $stage => $env) {
         $result['body']['environments'][$stage]['secret'] = base64_decode($env['secret']);
     }
     $form['envs'] = array('#type' => 'value', '#value' => $result['body']['environments']);
     $envs = array();
     foreach (array_keys($result['body']['environments']) as $env) {
         $envs[$env] = Unicode::ucfirst($env);
     }
     if (count($result['body']['environments']) > 1) {
         $form['environment'] = array('#type' => 'select', '#title' => $this->t('Select environment for migration'), '#options' => $envs, '#description' => $this->t('Select which environment your site should be migrated to. Only environments that are running trunk or branch can be overwritten by migration. Environments running a tag are not included.'));
     } else {
         $form['environment'] = array('#markup' => $this->t('Available environment for migration: %env', array('%env' => array_pop($envs))));
     }
     $form['migrate_files'] = array('#type' => 'checkbox', '#title' => $this->t('Migrate files directory'), '#description' => $this->t('Include files directory and all files in migration. If you are experiencing migration errors it is recommended you do not send the files directory.'), '#default_value' => $config->get('migrate.files'));
     $form['reduce_db_size'] = array('#type' => 'checkbox', '#title' => $this->t('Reduce database export size'), '#description' => $this->t('Reduce the database export size by excluding the data from cache, session, and watchdog tables. If you are experiencing migration errors this is recommended. Table structure will still be exported.'), '#default_value' => 0);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Migrate'));
     $form['actions']['cancel'] = array('#type' => 'submit', '#value' => $this->t('Cancel'), '#submit' => ['::submitMigrateCancel']);
     return $form;
 }
  /**
   * Test File (Field) Paths Pathauto UI.
   */
  public function testUi() {
    // Create a File field.
    $field_name = Unicode::strtolower($this->randomMachineName());
    $this->createFileField($field_name, 'node', $this->contentType);

    // Ensure File (Field) Paths Pathauto settings are present and available.
    $this->drupalGet("admin/structure/types/manage/{$this->contentType}/fields/node.{$this->contentType}.{$field_name}");
    foreach (['path', 'name'] as $field) {
      $this->assertField("third_party_settings[filefield_paths][file_{$field}][options][pathauto]", t('Pathauto checkbox is present in File @field settings.', ['@field' => Unicode::ucfirst($field)]));

      $element = $this->xpath('//input[@name=:name]/@disabled', [':name' => "third_party_settings[filefield_paths][file_{$field}][options][pathauto]"]);
      $this->assert(empty($element), t('Pathauto checkbox is not disabled in File @field settings.', ['@field' => Unicode::ucfirst($field)]));
    }
  }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     // Use view mode of display settings.
     if ($this->entityType == 'node' && \Drupal::moduleHandler()->moduleExists('ds_switch_view_mode')) {
         $form['switch_fieldset'] = array('#type' => 'details', '#title' => t('Use view mode of display settings'), '#open' => $this->options['switch_fieldset']['switch']);
         $form['switch_fieldset']['switch'] = array('#type' => 'checkbox', '#title' => t('Use view mode of display settings'), '#default_value' => $this->options['switch_fieldset']['switch'], '#description' => t('Use the alternative view mode selected in the display settings tab.'));
     }
     // Alternating view modes.
     $form['alternating_fieldset'] = array('#type' => 'details', '#title' => t('Alternating view mode'), '#open' => $this->options['alternating_fieldset']['alternating']);
     $form['alternating_fieldset']['alternating'] = array('#type' => 'checkbox', '#title' => t('Use the changing view mode selector'), '#default_value' => $this->options['alternating_fieldset']['alternating']);
     $form['alternating_fieldset']['allpages'] = array('#type' => 'checkbox', '#title' => t('Use this configuration on every page. Otherwhise the default view mode is used as soon you browse away from the first page of this view.'), '#default_value' => isset($this->options['alternating_fieldset']['allpages']) ? $this->options['alternating_fieldset']['allpages'] : FALSE);
     $pager = $this->view->display_handler->getPlugin('pager');
     $limit = $pager->getItemsPerPage();
     if ($limit == 0 || $limit > 20) {
         $form['alternating_fieldset']['disabled'] = array('#markup' => t('This option is disabled because you have unlimited items or listing more than 20 items.'));
         $form['alternating_fieldset']['alternating']['#disabled'] = TRUE;
         $form['alternating_fieldset']['allpages']['#disabled'] = TRUE;
     } else {
         $i = 1;
         $a = 0;
         while ($limit != 0) {
             $form['alternating_fieldset']['item_' . $a] = ['#title' => t('Item @nr', array('@nr' => $i)), '#type' => 'select', '#default_value' => isset($this->options['alternating_fieldset']['item_' . $a]) ? $this->options['alternating_fieldset']['item_' . $a] : 'teaser', '#options' => \Drupal::service('entity_display.repository')->getViewModeOptions($this->entityTypeId)];
             $limit--;
             $a++;
             $i++;
         }
     }
     // Grouping rows
     $sorts = $this->view->display_handler->getOption('sorts');
     $groupable = !empty($sorts) && $this->options['grouping_fieldset']['group'];
     $form['grouping_fieldset'] = array('#type' => 'details', '#title' => t('Group data'), '#open' => $groupable);
     $form['grouping_fieldset']['group'] = array('#type' => 'checkbox', '#title' => t('Group data on a field. The value of this field will be displayed too.'), '#default_value' => $groupable);
     if (!empty($sorts)) {
         $sort_options = array();
         foreach ($sorts as $sort) {
             $sort_name = Unicode::ucfirst($sort['field']);
             $sort_options[$sort['table'] . '|' . $sort['field']] = $sort_name;
         }
         $form['grouping_fieldset']['group_field'] = array('#type' => 'select', '#options' => $sort_options, '#default_value' => isset($this->options['grouping_fieldset']['group_field']) ? $this->options['grouping_fieldset']['group_field'] : '');
         $form['grouping_fieldset']['group_field_function'] = array('#type' => 'textfield', '#title' => 'Heading function', '#description' => Html::escape(t('The value of the field can be in a very raw format (eg, date created). Enter a custom function which you can use to format that value. The value and the object will be passed into that function eg. custom_function($raw_value, $object);')), '#default_value' => isset($this->options['grouping_fieldset']['group_field_function']) ? $this->options['grouping_fieldset']['group_field_function'] : '');
     } else {
         $form['grouping_fieldset']['group']['#disabled'] = TRUE;
         $form['grouping_fieldset']['group']['#description'] = t('Grouping is disabled because you do not have any sort fields.');
     }
     // Advanced function.
     $form['advanced_fieldset'] = array('#type' => 'details', '#title' => t('Advanced view mode'), '#open' => $this->options['advanced_fieldset']['advanced']);
     $form['advanced_fieldset']['advanced'] = array('#type' => 'checkbox', '#title' => t('Use the advanced view mode selector'), '#description' => t('This gives you the opportunity to have full control of a list for really advanced features.<br /> There is no UI for this, you need to create a hook named like this: hook_ds_views_row_render_entity($entity, $view_mode).', array('@VIEWSNAME' => $this->view->storage->id())), '#default_value' => $this->options['advanced_fieldset']['advanced']);
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumbs = parent::build($route_match);
     $request = \Drupal::request();
     $path = trim($this->context->getPathInfo(), '/');
     $path_elements = explode('/', $path);
     $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
     if ($route && !\Drupal::service('router.admin_context')->isAdminRoute()) {
         $title = \Drupal::service('title_resolver')->getTitle($request, $route);
         if (!isset($title)) {
             // Fallback to using the raw path component as the title if the
             // route is missing a _title or _title_callback attribute.
             $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
         }
         $breadcrumbs->addLink(Link::createFromRoute($title, '<none>'));
     }
     return $breadcrumbs;
 }
 /**
  * Adds the default comment field to an entity.
  *
  * Attaches a comment field named 'comment' to the given entity type and
  * bundle. Largely replicates the default behavior in Drupal 7 and earlier.
  *
  * @param string $entity_type
  *   The entity type to attach the default comment field to.
  * @param string $bundle
  *   The bundle to attach the default comment field to.
  * @param string $field_name
  *   (optional) Field name to use for the comment field. Defaults to
  *     'comment'.
  * @param int $default_value
  *   (optional) Default value, one of CommentItemInterface::HIDDEN,
  *   CommentItemInterface::OPEN, CommentItemInterface::CLOSED. Defaults to
  *   CommentItemInterface::OPEN.
  * @param string $comment_type_id
  *   (optional) ID of comment type to use. Defaults to 'comment'.
  */
 public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment')
 {
     $entity_manager = \Drupal::entityManager();
     // Create the comment type if needed.
     $comment_type_storage = $entity_manager->getStorage('comment_type');
     if ($comment_type = $comment_type_storage->load($comment_type_id)) {
         if ($comment_type->getTargetEntityTypeId() !== $entity_type) {
             throw new \InvalidArgumentException(String::format('The given comment type id %id can only be used with the %entity_type entity type', array('%id' => $comment_type_id, '%entity_type' => $entity_type)));
         }
     } else {
         $comment_type_storage->create(array('id' => $comment_type_id, 'label' => Unicode::ucfirst($comment_type_id), 'target_entity_type_id' => $entity_type, 'description' => 'Default comment field'))->save();
     }
     // Add a body field to the comment type.
     \Drupal::service('comment.manager')->addBodyField($comment_type_id);
     // Add a comment field to the host entity type. Create the field storage if
     // needed.
     if (!array_key_exists($field_name, $entity_manager->getFieldStorageDefinitions($entity_type))) {
         $entity_manager->getStorage('field_storage_config')->create(array('entity_type' => $entity_type, 'field_name' => $field_name, 'type' => 'comment', 'translatable' => TRUE, 'settings' => array('comment_type' => $comment_type_id)))->save();
     }
     // Create the field if needed, and configure its form and view displays.
     if (!array_key_exists($field_name, $entity_manager->getFieldDefinitions($entity_type, $bundle))) {
         $entity_manager->getStorage('field_config')->create(array('label' => 'Comments', 'description' => '', 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'required' => 1, 'default_value' => array(array('status' => $default_value, 'cid' => 0, 'last_comment_name' => '', 'last_comment_timestamp' => 0, 'last_comment_uid' => 0))))->save();
         // Entity form displays: assign widget settings for the 'default' form
         // mode, and hide the field in all other form modes.
         entity_get_form_display($entity_type, $bundle, 'default')->setComponent($field_name, array('type' => 'comment_default', 'weight' => 20))->save();
         foreach ($entity_manager->getFormModes($entity_type) as $id => $form_mode) {
             $display = entity_get_form_display($entity_type, $bundle, $id);
             // Only update existing displays.
             if ($display && !$display->isNew()) {
                 $display->removeComponent($field_name)->save();
             }
         }
         // Entity view displays: assign widget settings for the 'default' view
         // mode, and hide the field in all other view modes.
         entity_get_display($entity_type, $bundle, 'default')->setComponent($field_name, array('label' => 'above', 'type' => 'comment_default', 'weight' => 20))->save();
         foreach ($entity_manager->getViewModes($entity_type) as $id => $view_mode) {
             $display = entity_get_display($entity_type, $bundle, $id);
             // Only update existing displays.
             if ($display && !$display->isNew()) {
                 $display->removeComponent($field_name)->save();
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * Transform a string by a certain method.
  *
  * @param $string
  *    The input you want to transform.
  * @param $option
  *    How do you want to transform it, possible values:
  *      - upper: Uppercase the string.
  *      - lower: lowercase the string.
  *      - ucfirst: Make the first char uppercase.
  *      - ucwords: Make each word in the string uppercase.
  *
  * @return string
  *    The transformed string.
  */
 protected function caseTransform($string, $option)
 {
     switch ($option) {
         default:
             return $string;
         case 'upper':
             return Unicode::strtoupper($string);
         case 'lower':
             return Unicode::strtolower($string);
         case 'ucfirst':
             return Unicode::ucfirst($string);
         case 'ucwords':
             return Unicode::ucwords($string);
     }
 }
Esempio n. 8
0
 /**
  * Builds a table row for the system modules page.
  *
  * @param array $modules
  *   The list existing modules.
  * @param \Drupal\Core\Extension\Extension $module
  *   The module for which to build the form row.
  * @param $distribution
  *
  * @return array
  *   The form row for the given module.
  */
 protected function buildRow(array $modules, Extension $module, $distribution)
 {
     // Set the basic properties.
     $row['#required'] = array();
     $row['#requires'] = array();
     $row['#required_by'] = array();
     $row['name']['#markup'] = $module->info['name'];
     $row['description']['#markup'] = $this->t($module->info['description']);
     $row['version']['#markup'] = $module->info['version'];
     // Generate link for module's help page, if there is one.
     $row['links']['help'] = array();
     if ($this->moduleHandler->moduleExists('help') && $module->status && in_array($module->getName(), $this->moduleHandler->getImplementations('help'))) {
         if ($this->moduleHandler->invoke($module->getName(), 'help', array('help.page.' . $module->getName(), $this->routeMatch))) {
             $row['links']['help'] = array('#type' => 'link', '#title' => $this->t('Help'), '#url' => Url::fromRoute('help.page', ['name' => $module->getName()]), '#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => $this->t('Help'))));
         }
     }
     // Generate link for module's permission, if the user has access to it.
     $row['links']['permissions'] = array();
     if ($module->status && \Drupal::currentUser()->hasPermission('administer permissions') && in_array($module->getName(), $this->moduleHandler->getImplementations('permission'))) {
         $row['links']['permissions'] = array('#type' => 'link', '#title' => $this->t('Permissions'), '#url' => Url::fromRoute('user.admin_permissions'), '#options' => array('fragment' => 'module-' . $module->getName(), 'attributes' => array('class' => array('module-link', 'module-link-permissions'), 'title' => $this->t('Configure permissions'))));
     }
     // Generate link for module's configuration page, if it has one.
     $row['links']['configure'] = array();
     if ($module->status && isset($module->info['configure'])) {
         $route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : array();
         if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
             $links = $this->menuLinkManager->loadLinksByRoute($module->info['configure']);
             /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
             $link = reset($links);
             // Most configure links have a corresponding menu link, though some just
             // have a route.
             if ($link) {
                 $description = $link->getDescription();
             } else {
                 $request = new Request();
                 $request->attributes->set('_route_name', $module->info['configure']);
                 $route_object = $this->routeProvider->getRouteByName($module->info['configure']);
                 $request->attributes->set('_route', $route_object);
                 $request->attributes->add($route_parameters);
                 $description = $this->titleResolver->getTitle($request, $route_object);
             }
             $row['links']['configure'] = array('#type' => 'link', '#title' => $this->t('Configure'), '#url' => Url::fromRoute($module->info['configure'], $route_parameters), '#options' => array('attributes' => array('class' => array('module-link', 'module-link-configure'), 'title' => $description)));
         }
     }
     // Present a checkbox for installing and indicating the status of a module.
     $row['enable'] = array('#type' => 'checkbox', '#title' => $this->t('Install'), '#default_value' => (bool) $module->status, '#disabled' => (bool) $module->status);
     // Disable the checkbox for required modules.
     if (!empty($module->info['required'])) {
         // Used when displaying modules that are required by the installation profile
         $row['enable']['#disabled'] = TRUE;
         $row['#required_by'][] = $distribution . (!empty($module->info['explanation']) ? ' (' . $module->info['explanation'] . ')' : '');
     }
     // Check the compatibilities.
     $compatible = TRUE;
     // Initialize an empty array of reasons why the module is incompatible. Add
     // each reason as a separate element of the array.
     $reasons = array();
     // Check the core compatibility.
     if ($module->info['core'] != \Drupal::CORE_COMPATIBILITY) {
         $compatible = FALSE;
         $reasons[] = $this->t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => \Drupal::CORE_COMPATIBILITY));
     }
     // Ensure this module is compatible with the currently installed version of PHP.
     if (version_compare(phpversion(), $module->info['php']) < 0) {
         $compatible = FALSE;
         $required = $module->info['php'] . (substr_count($module->info['php'], '.') < 2 ? '.*' : '');
         $reasons[] = $this->t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $required, '!php_version' => phpversion()));
     }
     // If this module is not compatible, disable the checkbox.
     if (!$compatible) {
         $status = implode(' ', $reasons);
         $row['enable']['#disabled'] = TRUE;
         $row['description']['#markup'] = $status;
         $row['#attributes']['class'][] = 'incompatible';
     }
     // If this module requires other modules, add them to the array.
     foreach ($module->requires as $dependency => $version) {
         if (!isset($modules[$dependency])) {
             $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">missing</span>)', array('@module' => Unicode::ucfirst($dependency)));
             $row['enable']['#disabled'] = TRUE;
         } elseif (empty($modules[$dependency]->hidden)) {
             $name = $modules[$dependency]->info['name'];
             // Disable the module's checkbox if it is incompatible with the
             // dependency's version.
             if ($incompatible_version = drupal_check_incompatibility($version, str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']))) {
                 $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> version @version)', array('@module' => $name . $incompatible_version, '@version' => $modules[$dependency]->info['version']));
                 $row['enable']['#disabled'] = TRUE;
             } elseif ($modules[$dependency]->info['core'] != \Drupal::CORE_COMPATIBILITY) {
                 $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', array('@module' => $name));
                 $row['enable']['#disabled'] = TRUE;
             } elseif ($modules[$dependency]->status) {
                 $row['#requires'][$dependency] = $this->t('@module', array('@module' => $name));
             } else {
                 $row['#requires'][$dependency] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $name));
             }
         }
     }
     // If this module is required by other modules, list those, and then make it
     // impossible to disable this one.
     foreach ($module->required_by as $dependent => $version) {
         if (isset($modules[$dependent]) && empty($modules[$dependent]->info['hidden'])) {
             if ($modules[$dependent]->status == 1 && $module->status == 1) {
                 $row['#required_by'][$dependent] = $this->t('@module', array('@module' => $modules[$dependent]->info['name']));
                 $row['enable']['#disabled'] = TRUE;
             } else {
                 $row['#required_by'][$dependent] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $modules[$dependent]->info['name']));
             }
         }
     }
     return $row;
 }
 /**
  * {@inheritdoc}
  */
 public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment')
 {
     $comment_type_storage = $this->entityManager->getStorage('comment_type');
     if ($comment_type = $comment_type_storage->load($comment_type_id)) {
         if ($comment_type->getTargetEntityTypeId() !== $entity_type) {
             throw new \InvalidArgumentException(String::format('The given comment type id %id can only be used with the %entity_type entity type', array('%id' => $comment_type_id, '%entity_type' => $entity_type)));
         }
     } else {
         // Silently create the comment-type for the calling code.
         $comment_type_storage->create(array('id' => $comment_type_id, 'label' => Unicode::ucfirst($comment_type_id), 'target_entity_type_id' => $entity_type, 'description' => 'Default comment field'))->save();
     }
     // Make sure the field doesn't already exist.
     if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
         // Add a default comment field for existing node comments.
         $field_storage = $this->entityManager->getStorage('field_storage_config')->create(array('entity_type' => $entity_type, 'field_name' => $field_name, 'type' => 'comment', 'translatable' => TRUE, 'settings' => array('comment_type' => $comment_type_id)));
         // Create the field.
         $field_storage->save();
     }
     // Make sure the instance doesn't already exist.
     if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) {
         $field = $this->entityManager->getStorage('field_config')->create(array('label' => 'Comments', 'description' => '', 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'required' => 1, 'default_value' => array(array('status' => $default_value, 'cid' => 0, 'last_comment_name' => '', 'last_comment_timestamp' => 0, 'last_comment_uid' => 0))));
         $field->save();
         // Assign widget settings for the 'default' form mode.
         entity_get_form_display($entity_type, $bundle, 'default')->setComponent($field_name, array('type' => 'comment_default', 'weight' => 20))->save();
         // The comment field should be hidden in all other form displays.
         foreach ($this->entityManager->getFormModes($entity_type) as $id => $form_mode) {
             $display = entity_get_form_display($entity_type, $bundle, $id);
             // Only update existing displays.
             if ($display && !$display->isNew()) {
                 $display->removeComponent($field_name)->save();
             }
         }
         // Set default to display comment list.
         entity_get_display($entity_type, $bundle, 'default')->setComponent($field_name, array('label' => 'above', 'type' => 'comment_default', 'weight' => 20))->save();
         // The comment field should be hidden in all other view displays.
         foreach ($this->entityManager->getViewModes($entity_type) as $id => $view_mode) {
             $display = entity_get_display($entity_type, $bundle, $id);
             // Only update existing displays.
             if ($display && !$display->isNew()) {
                 $display->removeComponent($field_name)->save();
             }
         }
     }
     $this->addBodyField($comment_type_id);
 }
 /**
  * Initializes the local cache for language path processors.
  *
  * @param string $scope
  *   The scope of the processors: "inbound" or "outbound".
  */
 protected function initProcessors($scope)
 {
     $interface = '\\Drupal\\Core\\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
     $this->processors[$scope] = array();
     foreach ($this->languageManager->getLanguageTypes() as $type) {
         foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
             if (!isset($this->processors[$scope][$method_id])) {
                 $reflector = new \ReflectionClass($method['class']);
                 if ($reflector->implementsInterface($interface)) {
                     $this->processors[$scope][$method_id] = $this->negotiator->getNegotiationMethodInstance($method_id);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $links = array();
     // General path-based breadcrumbs. Use the actual request path, prior to
     // resolving path aliases, so the breadcrumb can be defined by simply
     // creating a hierarchy of path aliases.
     $path = trim($this->context->getPathInfo(), '/');
     $path_elements = explode('/', $path);
     $exclude = array();
     // Don't show a link to the front-page path.
     $front = $this->config->get('page.front');
     $exclude[$front] = TRUE;
     // /user is just a redirect, so skip it.
     // @todo Find a better way to deal with /user.
     $exclude['user'] = TRUE;
     while (count($path_elements) > 1) {
         array_pop($path_elements);
         // Copy the path elements for up-casting.
         $route_request = $this->getRequestForPath(implode('/', $path_elements), $exclude);
         if ($route_request) {
             $access = $this->accessManager->checkRequest($route_request, $this->currentUser);
             if ($access) {
                 $title = $this->titleResolver->getTitle($route_request, $route_request->attributes->get(RouteObjectInterface::ROUTE_OBJECT));
             }
             if ($access) {
                 if (!isset($title)) {
                     // Fallback to using the raw path component as the title if the
                     // route is missing a _title or _title_callback attribute.
                     $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
                 }
                 $links[] = Link::createFromRoute($title, $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME), $route_request->attributes->get('_raw_variables')->all());
             }
         }
     }
     if ($path && $path != $front) {
         // Add the Home link, except for the front page.
         $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     }
     return array_reverse($links);
 }
Esempio n. 12
0
/**
 * Implements hook_form_system_theme_settings_alter().
 *
 * Custom theme settings
 */
function mayo_form_system_theme_settings_alter(&$form, FormStateInterface $form_state)
{
    global $base_url;
    //Change collapsible fieldsets (now details) to default #open => FALSE.
    $form['theme_settings']['#open'] = FALSE;
    $form['logo']['#open'] = FALSE;
    $form['favicon']['#open'] = FALSE;
    // Add various settings into drupalSettings for the live preview.
    $uri = theme_get_setting('logo.path', 'mayo');
    if (!empty($uri)) {
        $file_url = file_create_url($uri);
        $file_url = str_ireplace($base_url, '', $file_url);
    } else {
        $file_url = '/' . drupal_get_path('theme', 'mayo') . '/logo.svg';
    }
    $js = array('logo_path' => $file_url, 'header_bg_file' => theme_get_setting('header_bg_file', 'mayo'), 'header_bg_alignment' => theme_get_setting('header_bg_alignment', 'mayo'), 'header_watermark' => theme_get_setting('header_watermark', 'mayo'), 'header_border_width' => theme_get_setting('header_border_width', 'mayo'), 'layout_style' => theme_get_setting('layout_style', 'mayo'), 'base_vmargin' => theme_get_setting('base_vmargin', 'mayo'));
    $form['#attached']['drupalSettings']['color'] = $js;
    // Get our plugin system functions.
    require_once drupal_get_path('theme', 'mayo') . '/inc/plugins.inc';
    // We need some getters.
    require_once drupal_get_path('theme', 'mayo') . '/inc/get.inc';
    $path_to_mayo = drupal_get_path('theme', 'mayo');
    // General "alters" use a form id. Settings should not be set here. The only
    // thing useful about this is if you need to alter the form for the running
    // theme and *not* the theme setting.
    // @see http://drupal.org/node/943212
    if (isset($form_id)) {
        return;
    }
    // Get an array of device groups with option values
    $device_group_options = page_layouts_device_group_options('mayo');
    // Unit options
    $unit_options = array('%' => '%', 'px' => 'px', 'em' => 'em');
    // Assign $options for each device group
    foreach ($device_group_options as $device_group => $options) {
        // About here we need to call a custom sort function, this is what we got for now
        sort($options, SORT_STRING);
        foreach ($options as $option) {
            if ($device_group === 'bigscreen') {
                $bigscreen_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
                // human readable option names for accessibility
            }
            if ($device_group === 'tablet_landscape') {
                $tablet_landscape_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
            }
            if ($device_group === 'tablet_portrait') {
                $tablet_portrait_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
            }
            if ($device_group === 'smalltouch_landscape') {
                $smalltouch_landscape_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
            }
        }
    }
    /* --------------- Font settings -------------- */
    $form['font'] = array('#type' => 'details', '#title' => t('Font settings'), '#open' => FALSE);
    $form['font']['base_font_size'] = array('#type' => 'select', '#title' => t('Base font size'), '#default_value' => theme_get_setting('base_font_size'), '#options' => array('75%' => '75% (=12px)', '81.25%' => '81.25% (=13px)', '87.5%' => '87.5% (=14px)', '93.75%' => '93.75% (=15px)', '100%' => '100% (=16px)', '112.5%' => '112.5% (=18px)'), '#description' => t('To support text size enlargement/reduction, percent ratio based on the browser\'s regular font size (which is mostly 16px) is used.'));
    $form['font']['base_font_family'] = array('#type' => 'select', '#title' => t('Base font family'), '#default_value' => theme_get_setting('base_font_family'), '#options' => array(0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'), 1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'), 2 => t('Custom')), '#description' => t('Font used for most part of the contents.'));
    $form['font']['base_custom_font_family'] = array('#type' => 'textfield', '#title' => t('Custom base font family'), '#default_value' => theme_get_setting('base_custom_font_family'), '#size' => 80, '#description' => t('Enter the base font-family you want to use. No need to start with <b>font-family:</b> and end with <b>;</b>. Just enter comma separated font names.'), '#prefix' => '<div id="base-custom-font-family-wrapper">', '#suffix' => '</div>');
    $form['font']['heading_font_family'] = array('#type' => 'select', '#title' => t('Heading font family (except for the site name and slogan)'), '#default_value' => theme_get_setting('heading_font_family'), '#options' => array(0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'), 1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'), 2 => t('Custom')), '#description' => t('Font used for the headings (h1, h2, h3, h4, h5). Font used for the site name and slogan can not be changed here. If you want to change it, please manually edit style.css in the theme\'s css subdirectory.'));
    $form['font']['heading_custom_font_family'] = array('#type' => 'textfield', '#title' => t('Custom heading font family'), '#default_value' => theme_get_setting('heading_custom_font_family'), '#size' => 80, '#description' => t('Enter the font-family you want to use for the headings. No need to start with <b>font-family:</b> and end with <b>;</b>. Just enter comma separated font names.'), '#prefix' => '<div id="heading-custom-font-family-wrapper">', '#suffix' => '</div>');
    /* --------------- Layout settings -------------- */
    $form['layout'] = array('#type' => 'details', '#title' => t('Layout settings'), '#collapsed' => TRUE, '#collapsible' => TRUE);
    $form['layout']['base_vmargin'] = array('#type' => 'textfield', '#title' => t('Base vertical (top/bottom) margin'), '#default_value' => theme_get_setting('base_vmargin'), '#size' => 12, '#maxlength' => 8, '#description' => t('Specify the base vertical (top/bottom) margin which is vertical spaces between page edge and browser screen in px.'), '#prefix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/base-layout.png')->toString() . '" /><br />');
    $form['layout']['page_margin'] = array('#type' => 'textfield', '#title' => t('Page margin'), '#default_value' => theme_get_setting('page_margin'), '#size' => 12, '#maxlength' => 8, '#description' => t('Specify the page margin which is spaces between page edge and contents in px.'));
    $form['layout']['layout_style'] = array('#type' => 'radios', '#title' => t('Layout style'), '#default_value' => theme_get_setting('layout_style'), '#options' => array(1 => t('1. Apply page margin to all (header, footer and main contents).'), 2 => t('2. Apply page margin to main contents only.')), '#description' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/page-layout.png')->toString() . '" /><br />' . t('When the layout 2 is selected, or header background image is selected, header borders are not drawn to make it look better.'));
    /* --------------- Responsive sidebar layout settings -------------- */
    /* -----------Big screen as in desktop pc monitor------------- */
    $form['layout']['bigscreen'] = array('#type' => 'details', '#title' => t('Big Screen Sidebar layout'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#attributes' => array('class' => array('mayo-layout-form')));
    // Big screen Layout
    $form['layout']['bigscreen']['bigscreen-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    // Options
    $form['layout']['bigscreen']['bigscreen-layout-wrapper']['bigscreen_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => str_replace('-', '_', theme_get_setting('bigscreen_layout')), '#options' => $bigscreen_options);
    // Sidebars
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'), '#collapsible' => FALSE);
    // Units
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('bigscreen_sidebar_unit'), '#options' => $unit_options);
    // Sidebar first
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => Html::escape(theme_get_setting('bigscreen_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array(array('input[name="bigscreen_layout"]' => array('value' => 'three_col_grail')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_right')))));
    // Sidebar second
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => Html::escape(theme_get_setting('bigscreen_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array(array('input[name="bigscreen_layout"]' => array('value' => 'three_col_grail')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_right')))));
    // Page width
    $form['layout']['bigscreen']['bigscreen-width-wrapper'] = array('#type' => 'details', '#title' => t('Set the page width'), '#description' => t('<strong>Set the page width</strong>'));
    // Unit
    $form['layout']['bigscreen']['bigscreen-width-wrapper']['bigscreen_page_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('bigscreen_page_unit'), '#options' => $unit_options);
    // Width
    $form['layout']['bigscreen']['bigscreen-width-wrapper']['bigscreen_page_width'] = array('#type' => 'textfield', '#title' => t('Page width'), '#default_value' => Html::escape(theme_get_setting('bigscreen_page_width')), '#size' => 4, '#maxlenght' => 4, '#required' => TRUE);
    // Media queries
    $form['layout']['bigscreen']['media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Standard Screen Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    // Media query
    $form['layout']['bigscreen']['media-queries-wrapper']['bigscreen_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => Html::escape(theme_get_setting('bigscreen_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100, '#required' => TRUE);
    /* ****************************************************************************
     *
     * Tablet
     *
     * ************************************************************************** */
    $form['layout']['tablet'] = array('#type' => 'details', '#title' => t('Tablet Sidebar Layout'), '#description' => t('<h3>Tablet Layout</h3><p>Tablet devices such as iPad, Android and Windows tablets have two orientations - landscape and portrait, which can also be thought of as wide and narrow tablets. You can configure a different layout for each orientation.</p>'), '#attributes' => array('class' => array('mayo-layout-form')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    /* ******************
     * Tablet landscape
     * **************** */
    $form['layout']['tablet']['landscape'] = array('#type' => 'details', '#title' => t('Landscape'), '#description' => t('<h4>Landscape tablet <span class="field-description-info">(wide)</span></h4>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Tablet landscape Layout options
    $form['layout']['tablet']['landscape']['tablet-landscape-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    // Options
    $form['layout']['tablet']['landscape']['tablet-landscape-layout-wrapper']['tablet_landscape_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => str_replace('-', '_', theme_get_setting('tablet_landscape_layout')), '#options' => $tablet_landscape_options);
    // Sidebars
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'));
    // Units
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_landscape_sidebar_unit'), '#options' => $unit_options);
    // Sidebar first
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right_stack')))));
    // Sidebar second
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('invisible' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right_stack'))), 'required' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')))));
    // Conditional messages for sidebar layouts
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet-landscape-sidebar-message-wrapper'] = array('#type' => 'details', '#states' => array('invisible' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')))));
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet-landscape-sidebar-message-wrapper']['message'] = array('#markup' => t('<div class="description">In this layout <em>Second sidebar</em> wraps below.</div>'));
    // Page width
    $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper'] = array('#type' => 'details', '#title' => t('Set the page width'), '#description' => t('<strong>Set the page width</strong>'));
    // Unit
    $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper']['tablet_landscape_page_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_landscape_page_unit'), '#options' => $unit_options);
    // Width
    $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper']['tablet_landscape_page_width'] = array('#type' => 'textfield', '#title' => t('Page width'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_page_width')), '#size' => 4, '#maxlenght' => 4, '#required' => TRUE);
    // Media Queries
    $form['layout']['tablet']['landscape']['tablet-landscape-media-queries-wrapper'] = array('#title' => t('Tablet Landscape Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    // Media query
    $form['layout']['tablet']['landscape']['tablet-landscape-media-queries-wrapper']['tablet_landscape_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100, '#required' => TRUE);
    /* *****************
     * Tablet portrait
     * *************** */
    $form['layout']['tablet']['portrait'] = array('#type' => 'details', '#title' => t('Portrait'), '#description' => t('<h4>Portrait tablet <span class="field-description-info">(narrow)</span></h4>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Tablet portrait Layout options
    $form['layout']['tablet']['portrait']['tablet-portrait-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    // Options
    $form['layout']['tablet']['portrait']['tablet-portrait-layout-wrapper']['tablet_portrait_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => str_replace('-', '_', theme_get_setting('tablet_portrait_layout')), '#options' => $tablet_portrait_options);
    // Tablet portrait Sidebars
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'), '#states' => array('invisible' => array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack'))));
    // Units
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_portrait_sidebar_unit'), '#options' => $unit_options);
    // Sidebar first
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('invisible' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack'))), 'required' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_right_stack')))));
    // Sidebar second
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('invisible' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_right_stack'))), 'required' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')))));
    // Conditional messages for sidebar layouts
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet-portrait-sidebar-message-wrapper'] = array('#type' => 'details', '#states' => array('invisible' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')), array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')))));
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet-portrait-sidebar-message-wrapper']['message'] = array('#markup' => t('<div class="description">In this layout <em>Second sidebar</em> wraps below.</div>'));
    // Tablet portrait Page width
    $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper'] = array('#type' => 'details', '#title' => t('Set the page width'), '#description' => t('<strong>Set the page width</strong>'));
    // Unit
    $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper']['tablet_portrait_page_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_portrait_page_unit'), '#options' => $unit_options);
    // Width
    $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper']['tablet_portrait_page_width'] = array('#type' => 'textfield', '#title' => t('Page width'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_page_width')), '#size' => 4, '#maxlenght' => 4, '#required' => TRUE);
    // Tablet portrait Media queries
    $form['layout']['tablet']['portrait']['tablet-portrait-media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Tablet Portrait Media Queries'), '#attributes' => array('class' => array('at-media-queries')));
    // Media query
    $form['layout']['tablet']['portrait']['tablet-portrait-media-queries-wrapper']['tablet_portrait_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100, '#required' => TRUE);
    /* ****************************************************************************
     *
     * Smalltouch
     *
     * ************************************************************************** */
    $form['layout']['smalltouch'] = array('#type' => 'details', '#title' => t('Smalltouch Sidebar Layout'), '#description' => t('<h3>Smalltouch Layout</h3><p>Smalltouch devices such as iPhone, Android and Windows phones have two orientations - landscape and portrait, which can also be thought of as wide and arrow smalltouch devices. You can configure a layout for landscape orientation only - portrait orientation (narrow) will always display in one column (all regions full width and stacked) with sidebars below the main content.</p>'), '#attributes' => array('class' => array('mayo-layout-form')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    /* **********************
     * Smalltouch landscape
     * ******************** */
    $form['layout']['smalltouch']['landscape'] = array('#type' => 'details', '#title' => t('Landscape'), '#description' => t('<h4>Landscape smalltouch <span class="field-description-info">(wide)</span></h4>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-layout-wrapper']['smalltouch_landscape_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => theme_get_setting('smalltouch_landscape_layout') ? str_replace('-', '_', theme_get_setting('smalltouch_landscape_layout')) : str_replace('-', '_', theme_get_setting('smartphone_landscape_layout')), '#options' => $smalltouch_landscape_options);
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'), '#states' => array('!visible' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_stack'))));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_unit') ? theme_get_setting('smalltouch_landscape_sidebar_unit') : theme_get_setting('smartphone_landscape_sidebar_unit'), '#options' => $unit_options);
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_first') ? Html::escape(theme_get_setting('smalltouch_landscape_sidebar_first')) : Html::escape(theme_get_setting('smartphone_landscape_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_vert'))));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_second') ? Html::escape(theme_get_setting('smalltouch_landscape_sidebar_second')) : Html::escape(theme_get_setting('smartphone_landscape_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_vert'))));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Smalltouch Landscape Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-media-queries-wrapper']['smalltouch_landscape_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => theme_get_setting('smalltouch_landscape_media_query') ? Html::escape(theme_get_setting('smalltouch_landscape_media_query')) : Html::escape(theme_get_setting('smartphone_landscape_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100);
    // Pass hidden values to the sumbit function, these values are required but the user can't change them via the UI
    $form['layout']['smalltouch']['landscape']['hidden']['smalltouch_landscape_page_width'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_landscape_page_width') ? Html::escape(theme_get_setting('smalltouch_landscape_page_width')) : Html::escape(theme_get_setting('smartphone_landscape_page_width')));
    $form['layout']['smalltouch']['landscape']['hidden']['smalltouch_landscape_page_unit'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_landscape_page_unit') ? theme_get_setting('smalltouch_landscape_page_unit') : theme_get_setting('smartphone_landscape_page_unit'));
    /* *********************
     * Smalltouch portrait
     * ******************* */
    $form['layout']['smalltouch']['portrait'] = array('#type' => 'details', '#title' => t('Portrait'), '#description' => t('<h4>Portrait smalltouch <span class="field-description-info">(narrow)</span></h4><div class="smalltouch-portrait-layout">One column</div><p>The smalltouch portrait layout always displays in one column with sidebars stacked horizontally below the main content. All widths are always 100%.</p>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['layout']['smalltouch']['portrait']['smalltouch-portrait-media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Smalltouch Portrait Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    $form['layout']['smalltouch']['portrait']['smalltouch-portrait-media-queries-wrapper']['smalltouch_portrait_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => theme_get_setting('smalltouch_portrait_media_query') ? Html::escape(theme_get_setting('smalltouch_portrait_media_query')) : Html::escape(theme_get_setting('smartphone_portrait_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100);
    // Pass hidden values to the sumbit function, these values are required but the user can't change them via the UI
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_page_width'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_page_width') ? Html::escape(theme_get_setting('smalltouch_portrait_page_width')) : Html::escape(theme_get_setting('smartphone_portrait_page_width')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_page_unit'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_page_unit') ? theme_get_setting('smalltouch_portrait_page_unit') : theme_get_setting('smartphone_portrait_page_unit'));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_first'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_first') ? Html::escape(theme_get_setting('smalltouch_portrait_sidebar_first')) : Html::escape(theme_get_setting('smartphone_portrait_sidebar_first')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_second'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_second') ? Html::escape(theme_get_setting('smalltouch_portrait_sidebar_second')) : Html::escape(theme_get_setting('smartphone_portrait_sidebar_second')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_unit'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_unit') ? Html::escape(theme_get_setting('smalltouch_portrait_sidebar_unit')) : Html::escape(theme_get_setting('smartphone_portrait_sidebar_unit')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_layout'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_layout') ? str_replace('-', '_', theme_get_setting('smalltouch_portrait_layout')) : str_replace('-', '_', theme_get_setting('smartphone_portrait_layout')));
    /* --------------- Style settings -------------- */
    $form['style'] = array('#type' => 'details', '#title' => t('Style settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['style']['round_corners'] = array('#type' => 'select', '#title' => t('Content box round corners'), '#default_value' => theme_get_setting('round_corners'), '#description' => t('Make the corner of sidebar block and/or node rounded.'), '#options' => array('rc-0' => t('No round corners'), 'rc-1' => t('Sidebar block only'), 'rc-2' => t('Node only'), 'rc-3' => t('Both sidebar block and node')), '#suffix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/round-corners.png')->toString() . '" /><br />');
    $form['style']['menubar_style'] = array('#type' => 'radios', '#title' => t('Menubar style'), '#default_value' => theme_get_setting('menubar_style'), '#options' => array(1 => t('1. Normal (based on the colors specified by the color set)'), 2 => t('2. Gloss black image background.')), '#suffix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/menubar-type.png')->toString() . '" />');
    $form['style']['note'] = array('#type' => 'item', '#title' => t('Note:'), '#markup' => t('When the menubar type 2 is selected, the menu text color, menu highlight color, menu divier color from the color set are ignored and the fixed colors that match to the menubar are used instead.  Besides, highlight color and menu divider color from the color set are still used for other places such as tabs and sub-menubar for superfish and nice_menus menu.'));
    $form['style']['menubar_background'] = array('#type' => 'checkbox', '#title' => t('Allow Menubar background color.'), '#default_value' => theme_get_setting('menubar_background'), '#description' => t('Add your own hex background color below.'));
    $form['style']['menubar_bg_value'] = array('#type' => 'textfield', '#title' => t('Meubar background color'), '#default_value' => theme_get_setting('menubar_bg_value'), '#size' => 7, '#maxlength' => 7, '#description' => t('Specify the background color for the menubar. This setting is used only when the <em>Allow Meubar background</em> option is checked above.'));
    /* --------------- Advanced header settings -------------- */
    $form['adv_header'] = array('#type' => 'details', '#title' => t('Advanced header settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['adv_header']['header_searchbox'] = array('#type' => 'checkbox', '#title' => t('Add search form to the header'), '#default_value' => theme_get_setting('header_searchbox'), '#description' => t('Check here if you want to add search form block to the right side of the header. Search module must be enabled for this to work.'));
    $form['adv_header']['header_fontsizer'] = array('#type' => 'checkbox', '#title' => t('Add font resizing controls'), '#default_value' => theme_get_setting('header_fontsizer'), '#description' => t('Check here if you want to add font resizing controls at side of the header.'));
    $form['adv_header']['header_border_width'] = array('#type' => 'textfield', '#title' => t('Header border width'), '#default_value' => theme_get_setting('header_border_width'), '#size' => 12, '#maxlength' => 8, '#description' => t('Specify the header border width in px. Note that header border is not drawn when you use header background image or when you use layout style 2.'));
    $form['adv_header']['searchbox_size'] = array('#type' => 'textfield', '#title' => t('Search form textfield width'), '#default_value' => theme_get_setting('searchbox_size'), '#size' => 10, '#maxlength' => 6, '#description' => t('Specify the width of the text field of the search forms in characters. This size is also applied for the search form in a block. NOTE: do not add px since this is not px size.'));
    $form['adv_header']['header_bg_file'] = array('#type' => 'textfield', '#title' => t('URL of the header background image'), '#default_value' => theme_get_setting('header_bg_file'), '#description' => t('Enter a URL of the form (/sites/default/files/your-background.jpg). If the background image is bigger than the header area, it is clipped. If it\'s smaller than the header area, it is tiled to fill the header area. To remove the background image, blank this field and save the settings.'), '#size' => 40, '#maxlength' => 120);
    $form['adv_header']['header_bg'] = array('#type' => 'file', '#title' => t('Upload header background image'), '#size' => 40, '#attributes' => array('enctype' => 'multipart/form-data'), '#description' => t('If you don\'t jave direct access to the server, use this field to upload your header background image. Uploads limited to .png .gif .jpg .jpeg .apng .svg extensions'), '#element_validate' => array('mayo_header_bg_validate'));
    $form['adv_header']['header_bg_alignment'] = array('#type' => 'select', '#title' => t('Header backgeround image alignment'), '#default_value' => theme_get_setting('header_bg_alignment'), '#description' => t('Select the alignment of the header background image.'), '#options' => array('top left' => t('Top left'), 'top center' => t('Top center'), 'top right' => t('Top right'), 'center left' => t('Center left'), 'center center' => t('Center center'), 'center right' => t('Center right'), 'bottom left' => t('Bottom left'), 'bottom center' => t('Bottom center'), 'bottom right' => t('Bottom right')));
    $form['adv_header']['header_watermark'] = array('#type' => 'select', '#title' => t('Header watermark'), '#default_value' => theme_get_setting('header_watermark'), '#description' => t('Select the watermark you want from the list below. The sample below is scaled down and the actual size of the watermark is bigger.'), '#options' => array(0 => t('-None-'), 1 => t('Pixture'), 2 => t('Wave'), 3 => t('Bubble'), 4 => t('Flower'), 5 => t('Star'), 6 => t('Metal')), '#suffix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/watermark-sample.png')->toString() . '" /><br />');
    /* --------------- Misellanenous settings -------------- */
    $form['misc'] = array('#type' => 'details', '#title' => t('Miscellaneous settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['misc']['dark_messages'] = array('#type' => 'checkbox', '#title' => t('Use dark message colors'), '#default_value' => theme_get_setting('dark_messages'), '#return_value' => 'dark-messages', '#description' => t('Check here if you use the dark color set. Colors for the status/warning/error messages are adjusted.'));
    /*
     * Originally posted by dvessel (http://drupal.org/user/56782).
     * The following will be processed even if the theme is inactive.
     * If you are on a theme specific settings page but it is not an active
     * theme (example.com/admin/apearance/settings/THEME_NAME), it will
     * still be processed.
     *
     * Build a list of themes related to the theme specific form. If the form
     * is specific to a sub-theme, all parent themes leading to it will have
     * hook_form_theme_settings invoked. For example, if a theme named
     * 'grandchild' has its settings form in focus, the following will be invoked.
     * - parent_form_theme_settings()
     * - child_form_theme_settings()
     * - grandchild_form_theme_settings()
     *
     * If 'child' was in focus it will invoke:
     * - parent_form_theme_settings()
     * - child_form_theme_settings()
     *
     *  @see http://drupal.org/node/943212
     */
    $form_themes = array();
    $theme_handler = \Drupal::service('theme_handler');
    $themes = $theme_handler->listInfo();
    // Get a list of available themes.
    $_theme = \Drupal::theme()->getActiveTheme()->getName();
    while (isset($_theme)) {
        $form_themes[$_theme] = $_theme;
        $_theme = isset($themes[$_theme]->base_theme) ? $themes[$_theme]->base_theme : NULL;
    }
    $form_themes = array_reverse($form_themes);
    foreach ($form_themes as $theme_key) {
        if (function_exists($form_settings = "{$theme_key}_form_theme_settings")) {
            $form_settings($form, $form_state);
        }
    }
    // Include custom form validation and submit functions
    require_once drupal_get_path('theme', 'mayo') . '/inc/forms/mayo.validate.inc';
    require_once drupal_get_path('theme', 'mayo') . '/inc/forms/mayo.submit.inc';
    // Custom validate and submit functions
    // Custom submit buggy. Edited FormBuilder.php with patch in #12
    // found here: https://drupal.org/node/2252165
    $form['#validate'][] = 'mayo_settings_validate';
    $form['#submit'][] = 'mayo_settings_submit';
}
Esempio n. 13
0
 /**
  * Tests multibyte ucfirst.
  *
  * @dataProvider providerUcfirst
  * @covers ::ucfirst
  */
 public function testUcfirst($text, $expected)
 {
     $this->assertEquals($expected, Unicode::ucfirst($text));
 }
Esempio n. 14
0
 protected function applyModifiers($string, $modifiers)
 {
     if (!is_null($string) || strlen($string)) {
         if ($modifiers) {
             $original_string = $string;
             $prefix = '';
             $suffix = '';
             if (preg_match('/^(<span[^>]*>)(.*)(<\\/span>)$/i', $string, $matches)) {
                 $prefix = $matches[1];
                 $string = $matches[2];
                 $suffix = $matches[3];
             }
             for ($j = 0; $j < strlen($modifiers); $j++) {
                 switch ($modifiers[$j]) {
                     case 'L':
                         $string = Unicode::strtolower($string);
                         break;
                     case 'U':
                         $string = Unicode::strtoupper($string);
                         break;
                     case 'F':
                         $string = Unicode::ucfirst($string);
                         break;
                     case 'G':
                         if (!empty($string)) {
                             $parts = explode(' ', $string);
                             $string = array();
                             foreach ($parts as $part) {
                                 $string[] = Unicode::ucfirst($part);
                             }
                             $string = implode(' ', $string);
                         }
                         break;
                     case 'T':
                         $string = trim($string);
                         break;
                     case 'S':
                         $string = SafeMarkup::checkPlain($string);
                         break;
                 }
             }
             $string = $prefix . $string . $suffix;
         }
     }
     return $string;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $links = array();
     // General path-based breadcrumbs. Use the actual request path, prior to
     // resolving path aliases, so the breadcrumb can be defined by simply
     // creating a hierarchy of path aliases.
     $path = trim($this->context->getPathInfo(), '/');
     $path_elements = explode('/', $path);
     $exclude = array();
     // Don't show a link to the front-page path.
     $front = $this->config->get('page.front');
     $exclude[$front] = TRUE;
     // /user is just a redirect, so skip it.
     // @todo Find a better way to deal with /user.
     $exclude['/user'] = TRUE;
     // Because this breadcrumb builder is entirely path-based, vary by the
     // 'url.path' cache context.
     $breadcrumb->addCacheContexts(['url.path']);
     while (count($path_elements) > 1) {
         array_pop($path_elements);
         // Copy the path elements for up-casting.
         $route_request = $this->getRequestForPath('/' . implode('/', $path_elements), $exclude);
         if ($route_request) {
             $route_match = RouteMatch::createFromRequest($route_request);
             $access = $this->accessManager->check($route_match, $this->currentUser, NULL, TRUE);
             // The set of breadcrumb links depends on the access result, so merge
             // the access result's cacheability metadata.
             $breadcrumb = $breadcrumb->addCacheableDependency($access);
             if ($access->isAllowed()) {
                 $title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject());
                 if (!isset($title)) {
                     // Fallback to using the raw path component as the title if the
                     // route is missing a _title or _title_callback attribute.
                     $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
                 }
                 $url = Url::fromRouteMatch($route_match);
                 $links[] = new Link($title, $url);
             }
         }
     }
     if ($path && '/' . $path != $front) {
         // Add the Home link, except for the front page.
         $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     }
     return $breadcrumb->setLinks(array_reverse($links));
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $field_key = '')
 {
     // Initialize field.
     $field = array();
     // Fetch field if it already exists.
     if (!empty($field_key)) {
         $field = $this->config('ds.field.' . $field_key)->get();
     }
     // Save the field for future reuse.
     $this->field = $field;
     $form['name'] = array('#title' => t('Label'), '#type' => 'textfield', '#default_value' => isset($field['label']) ? $field['label'] : '', '#description' => t('The human-readable label of the field.'), '#maxlength' => 128, '#required' => TRUE, '#size' => 30);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => isset($field['id']) ? $field['id'] : '', '#maxlength' => 32, '#description' => t('The machine-readable name of this field. This name must contain only lowercase letters and underscores. This name must be unique.'), '#disabled' => !empty($field['id']), '#machine_name' => array('exists' => array($this, 'uniqueFieldName'), 'source' => array('name')));
     $entity_options = array();
     $entities = $this->entityTypeManager->getDefinitions();
     foreach ($entities as $entity_type => $entity_info) {
         if ($entity_info->get('field_ui_base_route') || $entity_type == 'ds_views') {
             $entity_options[$entity_type] = Unicode::ucfirst(str_replace('_', ' ', $entity_type));
         }
     }
     $form['entities'] = array('#title' => t('Entities'), '#description' => t('Select the entities for which this field will be made available.'), '#type' => 'checkboxes', '#required' => TRUE, '#options' => $entity_options, '#default_value' => isset($field['entities']) ? $field['entities'] : array());
     $form['ui_limit'] = array('#title' => t('Limit field'), '#description' => t('Limit this field on field UI per bundles and/or view modes. The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'. You may use * to select all, e.g article|*, *|full or *|*. Enter one value per line.'), '#type' => 'textarea', '#default_value' => isset($field['ui_limit']) ? $field['ui_limit'] : '');
     $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 100);
     return $form;
 }
Esempio n. 17
0
 /**
  * Initializes the local cache for language path processors.
  *
  * @param string $scope
  *   The scope of the processors: "inbound" or "outbound".
  */
 protected function initProcessors($scope)
 {
     $interface = '\\Drupal\\Core\\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
     $this->processors[$scope] = array();
     $weights = [];
     foreach ($this->languageManager->getLanguageTypes() as $type) {
         foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
             if (!isset($this->processors[$scope][$method_id])) {
                 $reflector = new \ReflectionClass($method['class']);
                 if ($reflector->implementsInterface($interface)) {
                     $this->processors[$scope][$method_id] = $this->negotiator->getNegotiationMethodInstance($method_id);
                     $weights[$method_id] = $method['weight'];
                 }
             }
         }
     }
     // Sort the processors list, so that their functions are called in the
     // order specified by the weight of the methods.
     uksort($this->processors[$scope], function ($method_id_a, $method_id_b) use($weights) {
         $a_weight = $weights[$method_id_a];
         $b_weight = $weights[$method_id_b];
         if ($a_weight == $b_weight) {
             return 0;
         }
         return $a_weight < $b_weight ? -1 : 1;
     });
 }