/** * Gets the human-readable provider label. * * @param $provider string * * @return string */ protected function getProviderLabel($provider) { if ($provider == 'core') { return $this->t('Core'); } else { return $this->moduleHandler->getName($provider); } }
/** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $modules = $this->moduleHandler->getModuleList(); $names = array(); foreach (array_keys($modules) as $name) { $names[$name] = $this->moduleHandler->getName($name); } $form['data_module'] = array('#title' => $this->t('Module name'), '#type' => 'select', '#description' => $this->t('The module which sets this user data.'), '#default_value' => $this->options['data_module'], '#options' => $names); $form['data_name'] = array('#title' => $this->t('Name'), '#type' => 'textfield', '#description' => $this->t('The name of the data key.'), '#default_value' => $this->options['data_name']); }
/** * {@inheritdoc} */ public function listTopics() { $topics = []; foreach ($this->moduleHandler->getImplementations('help') as $module) { $title = $this->moduleHandler->getName($module); $topics[$title] = Link::createFromRoute($title, 'help.page', ['name' => $module]); } // Sort topics by title, which is the array key above. ksort($topics); return $topics; }
public function getValueOptions() { if (!isset($this->valueOptions)) { $permissions = $this->permissionHandler->getPermissions(); foreach ($permissions as $perm => $perm_item) { $provider = $perm_item['provider']; $display_name = $this->moduleHandler->getName($provider); $this->valueOptions[$display_name][$perm] = SafeMarkup::checkPlain(strip_tags($perm_item['title'])); } } else { return $this->valueOptions; } }
/** * Returns all module names. * * @return string[] * Returns the human readable names of all modules keyed by machine name. */ protected function getModuleNames() { $modules = array(); foreach (array_keys($this->moduleHandler->getModuleList()) as $module) { $modules[$module] = $this->moduleHandler->getName($module); } asort($modules); return $modules; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $role_names = array(); $role_permissions = array(); $admin_roles = array(); foreach ($this->getRoles() as $role_name => $role) { // Retrieve role names for columns. $role_names[$role_name] = $role->label(); // Fetch permissions for the roles. $role_permissions[$role_name] = $role->getPermissions(); $admin_roles[$role_name] = $role->isAdmin(); } // Store $role_names for use when saving the data. $form['role_names'] = array('#type' => 'value', '#value' => $role_names); // Render role/permission overview: $options = array(); $hide_descriptions = system_admin_compact_mode(); $form['system_compact_link'] = array('#id' => FALSE, '#type' => 'system_compact_link'); $form['permissions'] = array('#type' => 'table', '#header' => array($this->t('Permission')), '#id' => 'permissions', '#attributes' => ['class' => ['permissions', 'js-permissions']], '#sticky' => TRUE); foreach ($role_names as $name) { $form['permissions']['#header'][] = array('data' => $name, 'class' => array('checkbox')); } $permissions = $this->permissionHandler->getPermissions(); $permissions_by_provider = array(); foreach ($permissions as $permission_name => $permission) { $permissions_by_provider[$permission['provider']][$permission_name] = $permission; } foreach ($permissions_by_provider as $provider => $permissions) { // Module name. $form['permissions'][$provider] = array(array('#wrapper_attributes' => array('colspan' => count($role_names) + 1, 'class' => array('module'), 'id' => 'module-' . $provider), '#markup' => $this->moduleHandler->getName($provider))); foreach ($permissions as $perm => $perm_item) { // Fill in default values for the permission. $perm_item += array('description' => '', 'restrict access' => FALSE, 'warning' => !empty($perm_item['restrict access']) ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : ''); $options[$perm] = $perm_item['title']; $form['permissions'][$perm]['description'] = array('#type' => 'inline_template', '#template' => '<div class="permission"><span class="title">{{ title }}</span>{% if description or warning %}<div class="description">{% if warning %}<em class="permission-warning">{{ warning }}</em> {% endif %}{{ description }}</div>{% endif %}</div>', '#context' => array('title' => $perm_item['title'])); // Show the permission description. if (!$hide_descriptions) { $form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description']; $form['permissions'][$perm]['description']['#context']['warning'] = $perm_item['warning']; } $options[$perm] = ''; foreach ($role_names as $rid => $name) { $form['permissions'][$perm][$rid] = array('#title' => $name . ': ' . $perm_item['title'], '#title_display' => 'invisible', '#wrapper_attributes' => array('class' => array('checkbox')), '#type' => 'checkbox', '#default_value' => in_array($perm, $role_permissions[$rid]) ? 1 : 0, '#attributes' => array('class' => array('rid-' . $rid, 'js-rid-' . $rid)), '#parents' => array($rid, $perm)); // Show a column of disabled but checked checkboxes. if ($admin_roles[$rid]) { $form['permissions'][$perm][$rid]['#disabled'] = TRUE; $form['permissions'][$perm][$rid]['#default_value'] = TRUE; } } } } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save permissions'), '#button_type' => 'primary'); $form['#attached']['library'][] = 'user/drupal.user.permissions'; return $form; }
/** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); // Build the list of all permissions grouped by module. $permissions = []; foreach ($this->permissionHandler->getPermissions() as $permission => $permission_item) { $provider = $permission_item['provider']; $display_name = $this->moduleHandler->getName($provider); $permissions[$display_name][$permission] = Html::escape($permission_item['title']); } $form['admin_permission'] = ['#type' => 'select', '#title' => $this->t('Admin permission'), '#description' => $this->t('Allows the current user to access the view even if the argument is a different user.'), '#options' => $permissions, '#empty_value' => '', '#default_value' => $this->options['admin_permission']]; }
public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); // Get list of permissions $perms = []; $permissions = $this->permissionHandler->getPermissions(); foreach ($permissions as $perm => $perm_item) { $provider = $perm_item['provider']; $display_name = $this->moduleHandler->getName($provider); $perms[$display_name][$perm] = strip_tags($perm_item['title']); } $form['perm'] = array('#type' => 'select', '#options' => $perms, '#title' => $this->t('Permission'), '#default_value' => $this->options['perm'], '#description' => $this->t('Only users with the selected permission flag will be able to access this display.')); }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['#title'] = $this->t('Edit menu link %title', array('%title' => $this->menuLink->getTitle())); $provider = $this->menuLink->getProvider(); $form['info'] = array('#type' => 'item', '#title' => $this->t('This link is provided by the @name module. The title and path cannot be edited.', array('@name' => $this->moduleHandler->getName($provider)))); $link = array('#type' => 'link', '#title' => $this->menuLink->getTitle(), '#url' => $this->menuLink->getUrlObject()); $form['path'] = array('link' => $link, '#type' => 'item', '#title' => $this->t('Link')); $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable menu link'), '#description' => $this->t('Menu links that are not enabled will not be listed in any menu.'), '#default_value' => $this->menuLink->isEnabled()); $form['expanded'] = array('#type' => 'checkbox', '#title' => t('Show as expanded'), '#description' => $this->t('If selected and this menu link has children, the menu will always appear expanded.'), '#default_value' => $this->menuLink->isExpanded()); $menu_parent = $this->menuLink->getMenuName() . ':' . $this->menuLink->getParent(); $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($menu_parent, $this->menuLink->getPluginId()); $form['menu_parent']['#title'] = $this->t('Parent link'); $form['menu_parent']['#description'] = $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'); $form['menu_parent']['#attributes']['class'][] = 'menu-title-select'; $delta = max(abs($this->menuLink->getWeight()), 50); $form['weight'] = array('#type' => 'number', '#min' => -$delta, '#max' => $delta, '#default_value' => $this->menuLink->getWeight(), '#title' => $this->t('Weight'), '#description' => $this->t('Link weight among links in the same menu at the same depth. In the menu, the links with high weight will sink and links with a low weight will be positioned nearer the top.')); return $form; }
/** * Generates a report about config updates. * * @param string $report_type * Type of report to generate: 'type', 'module', 'theme', or 'profile'. * @param string $value * Machine name of a configuration type, module, or theme to generate the * report for. Ignored for profile, since that uses the active profile. * * @return array * Render array for the updates report. Empty if invalid or missing * report type or value. */ protected function generateReport($report_type, $value) { // Figure out what to name the report, and incidentally, validate that // $value exists for this type of report. switch ($report_type) { case 'type': if ($value == 'system.all') { $label = $this->t('All configuration'); } elseif ($value == 'system.simple') { $label = $this->t('Simple configuration'); } else { $definition = $this->configList->getType($value); if (!$definition) { return NULL; } $label = $this->t('@name configuration', array('@name' => $definition->getLabel())); } break; case 'module': $list = $this->moduleHandler->getModuleList(); if (!isset($list[$value])) { return NULL; } $label = $this->t('@name module', array('@name' => $this->moduleHandler->getName($value))); break; case 'theme': $list = $this->themeHandler->listInfo(); if (!isset($list[$value])) { return NULL; } $label = $this->t('@name theme', array('@name' => $this->themeHandler->getName($value))); break; case 'profile': $profile = Settings::get('install_profile'); $label = $this->t('@name profile', array('@name' => $this->moduleHandler->getName($profile))); break; default: return NULL; } // List the active and extension-provided config. list($active_list, $install_list, $optional_list) = $this->configList->listConfig($report_type, $value); // Build the report. $build = array(); $build['#title'] = $this->t('Configuration updates report for @label', array('@label' => $label)); $build['report_header'] = array('#markup' => '<h3>' . $this->t('Updates report') . '</h3>'); // List items missing from site. $removed = array_diff($install_list, $active_list); $build['removed'] = array('#caption' => $this->t('Missing configuration items'), '#empty' => $this->t('None: all provided configuration items are in your active configuration.')) + $this->makeReportTable($removed, 'extension', array('import')); // List optional items that are not installed. $inactive = array_diff($optional_list, $active_list); $build['inactive'] = array('#caption' => $this->t('Inactive optional items'), '#empty' => $this->t('None: all optional configuration items are in your active configuration.')) + $this->makeReportTable($inactive, 'extension', array('import')); // List items added to site, which only makes sense in the report for a // config type. $added = array_diff($active_list, $install_list, $optional_list); if ($report_type == 'type') { $build['added'] = array('#caption' => $this->t('Added configuration items'), '#empty' => $this->t('None: all active configuration items of this type were provided by modules, themes, or install profile.')) + $this->makeReportTable($added, 'active', array('export', 'delete')); } // For differences, we need to go through the array of config in both // and see if each config item is the same or not. $both = array_diff($active_list, $added); $different = array(); foreach ($both as $name) { if (!$this->configDiff->same($this->configRevert->getFromExtension('', $name), $this->configRevert->getFromActive('', $name))) { $different[] = $name; } } $build['different'] = array('#caption' => $this->t('Changed configuration items'), '#empty' => $this->t('None: no active configuration items differ from their current provided versions.')) + $this->makeReportTable($different, 'active', array('diff', 'export', 'revert')); return $build; }
/** * Builds the details of a package. * * @param \Drupal\features\Package $package * The package. * * @return array * A render array of a form element. */ protected function buildPackageDetail(Package $package) { $config_collection = $this->featuresManager->getConfigCollection(); $url = Url::fromRoute('features.edit', array('featurename' => $package->getMachineName())); $element['name'] = array('data' => \Drupal::l($package->getName(), $url), 'class' => array('feature-name')); $machine_name = $package->getMachineName(); // Except for the 'unpackaged' pseudo-package, display the full name, since // that's what will be generated. if ($machine_name !== 'unpackaged') { $machine_name = $this->assigner->getBundle($package->getBundle())->getFullName($machine_name); } $element['machine_name'] = $machine_name; $element['status'] = array('data' => $this->featuresManager->statusLabel($package->getStatus()), 'class' => array('column-nowrap')); // Use 'data' instead of plain string value so a blank version doesn't // remove column from table. $element['version'] = array('data' => SafeMarkup::checkPlain($package->getVersion()), 'class' => array('column-nowrap')); $overrides = $this->featuresManager->detectOverrides($package); $new_config = $this->featuresManager->detectNew($package); $conflicts = array(); $missing = array(); if ($package->getStatus() == FeaturesManagerInterface::STATUS_NO_EXPORT) { $overrides = array(); $new_config = array(); } // Bundle package configuration by type. $package_config = array(); foreach ($package->getConfig() as $item_name) { $item = $config_collection[$item_name]; $package_config[$item->getType()][] = array('name' => SafeMarkup::checkPlain($item_name), 'label' => SafeMarkup::checkPlain($item->getLabel()), 'class' => in_array($item_name, $overrides) ? 'features-override' : (in_array($item_name, $new_config) ? 'features-detected' : '')); } // Conflict config from other modules. foreach ($package->getConfigOrig() as $item_name) { if (!isset($config_collection[$item_name])) { $missing[] = $item_name; $package_config['missing'][] = array('name' => SafeMarkup::checkPlain($item_name), 'label' => SafeMarkup::checkPlain($item_name), 'class' => 'features-conflict'); } elseif (!in_array($item_name, $package->getConfig())) { $item = $config_collection[$item_name]; $conflicts[] = $item_name; $package_config[$item->getType()][] = array('name' => SafeMarkup::checkPlain($item_name), 'label' => SafeMarkup::checkPlain($item->getLabel()), 'class' => 'features-conflict'); } } // Add dependencies. $package_config['dependencies'] = array(); foreach ($package->getDependencies() as $dependency) { $package_config['dependencies'][] = array('name' => $dependency, 'label' => $this->moduleHandler->getName($dependency), 'class' => ''); } $class = ''; $label = ''; if (!empty($conflicts)) { $url = Url::fromRoute('features.edit', array('featurename' => $package->getMachineName())); $class = 'features-conflict'; $label = $this->t('Conflicts'); } elseif (!empty($overrides)) { $url = Url::fromRoute('features.diff', array('featurename' => $package->getMachineName())); $class = 'features-override'; $label = $this->featuresManager->stateLabel(FeaturesManagerInterface::STATE_OVERRIDDEN); } elseif (!empty($new_config)) { $url = Url::fromRoute('features.diff', array('featurename' => $package->getMachineName())); $class = 'features-detected'; $label = $this->t('New detected'); } elseif (!empty($missing)) { $url = Url::fromRoute('features.edit', array('featurename' => $package->getMachineName())); $class = 'features-conflict'; $label = $this->t('Missing'); } if (!empty($class)) { $element['state'] = array('data' => \Drupal::l($label, $url), 'class' => array($class, 'column-nowrap')); } else { $element['state'] = ''; } $config_types = $this->featuresManager->listConfigTypes(); // Add dependencies. $config_types['dependencies'] = $this->t('Dependencies'); $config_types['missing'] = $this->t('Missing'); uasort($config_types, 'strnatcasecmp'); $rows = array(); // Use sorted array for order. foreach ($config_types as $type => $label) { // For each component type, offer alternating rows. $row = array(); if (isset($package_config[$type])) { $row[] = array('data' => array('#type' => 'html_tag', '#tag' => 'span', '#value' => SafeMarkup::checkPlain($label), '#attributes' => array('title' => SafeMarkup::checkPlain($type), 'class' => 'features-item-label'))); $row[] = array('data' => array('#theme' => 'features_items', '#items' => $package_config[$type], '#value' => SafeMarkup::checkPlain($label), '#title' => SafeMarkup::checkPlain($type)), 'class' => 'item'); $rows[] = $row; } } $element['table'] = array('#type' => 'table', '#rows' => $rows); $details = array(); $details['description'] = array('#markup' => Xss::filterAdmin($package->getDescription())); $details['table'] = array('#type' => 'details', '#title' => array('#markup' => $this->t('Included configuration')), '#description' => array('data' => $element['table'])); $element['details'] = array('class' => array('description', 'expand'), 'data' => $details); return $element; }