/** * Performs language negotiation using the specified negotiation method. * * @param string $type * The language type to be initialized. * @param string $method_id * The string identifier of the language negotiation method to use to detect * language. * * @return \Drupal\Core\Language\LanguageInterface|null * Negotiated language object for given type and method, FALSE otherwise. */ protected function negotiateLanguage($type, $method_id) { $langcode = NULL; $method = $this->negotiatorManager->getDefinition($method_id); if (!isset($method['types']) || in_array($type, $method['types'])) { $langcode = $this->getNegotiationMethodInstance($method_id)->getLangcode($this->requestStack->getCurrentRequest()); } $languages = $this->languageManager->getLanguages(); return isset($languages[$langcode]) ? $languages[$langcode] : NULL; }
/** * Gets a list of displays included in the view. * * @param \Drupal\Core\Entity\EntityInterface $view * The view entity instance to get a list of displays for. * * @return array * An array of display types that this view includes. */ protected function getDisplaysList(EntityInterface $view) { $displays = array(); foreach ($view->get('display') as $display) { $definition = $this->displayManager->getDefinition($display['display_plugin']); if (!empty($definition['admin'])) { // Cast the admin label to a string since it is an object. // @see \Drupal\Core\StringTranslation\TranslatableMarkup $displays[] = (string) $definition['admin']; } } sort($displays); return $displays; }
/** * Performs language negotiation using the specified negotiation method. * * @param string $type * The language type to be initialized. * @param string $method_id * The string identifier of the language negotiation method to use to detect * language. * * @return \Drupal\Core\Language\LanguageInterface|null * Negotiated language object for given type and method, FALSE otherwise. */ protected function negotiateLanguage($type, $method_id) { $langcode = NULL; $method = $this->negotiatorManager->getDefinition($method_id); if (!isset($method['types']) || in_array($type, $method['types'])) { // Check for a cache mode force from settings.php. if ($this->settings->get('page_cache_without_database')) { $cache_enabled = TRUE; } else { $cache_enabled = $this->configFactory->get('system.performance')->get('cache.page.use_internal'); } // If the language negotiation method has no cache preference or this is // satisfied we can execute the callback. if ($cache = !isset($method['cache']) || $this->currentUser->isAuthenticated() || $method['cache'] == $cache_enabled) { $langcode = $this->getNegotiationMethodInstance($method_id)->getLangcode($this->requestStack->getCurrentRequest()); } } $languages = $this->languageManager->getLanguages(); return isset($languages[$langcode]) ? $languages[$langcode] : NULL; }
/** * Additional #pre_render callback for 'text_format' elements. */ function preRenderTextFormat(array $element) { // Allow modules to programmatically enforce no client-side editor by // setting the #editor property to FALSE. if (isset($element['#editor']) && !$element['#editor']) { return $element; } // filter_process_format() copies properties to the expanded 'value' child // element, including the #pre_render property. Skip this text format // widget, if it contains no 'format'. if (!isset($element['format'])) { return $element; } $format_ids = array_keys($element['format']['format']['#options']); // Early-return if no text editor is associated with any of the text formats. $editors = Editor::loadMultiple($format_ids); foreach ($editors as $key => $editor) { $definition = $this->pluginManager->getDefinition($editor->getEditor()); if (!in_array($element['#base_type'], $definition['supported_element_types'])) { unset($editors[$key]); } } if (count($editors) === 0) { return $element; } // Use a hidden element for a single text format. $field_id = $element['value']['#id']; if (!$element['format']['format']['#access']) { // Use the first (and only) available text format. $format_id = $format_ids[0]; $element['format']['editor'] = array('#type' => 'hidden', '#name' => $element['format']['format']['#name'], '#value' => $format_id, '#attributes' => array('class' => array('editor'), 'data-editor-for' => $field_id)); } else { $element['format']['format']['#attributes']['class'][] = 'editor'; $element['format']['format']['#attributes']['data-editor-for'] = $field_id; } // Hide the text format's filters' guidelines of those text formats that have // a text editor associated: they're rather useless when using a text editor. foreach ($editors as $format_id => $editor) { $element['format']['guidelines'][$format_id]['#access'] = FALSE; } // Attach Text Editor module's (this module) library. $element['#attached']['library'][] = 'editor/drupal.editor'; // Attach attachments for all available editors. $element['#attached'] = drupal_merge_attached($element['#attached'], $this->pluginManager->getAttachments($format_ids)); // Apply XSS filters when editing content if necessary. Some types of text // editors cannot guarantee that the end user won't become a victim of XSS. if (!empty($element['value']['#value'])) { $original = $element['value']['#value']; $format = FilterFormat::load($element['format']['format']['#value']); // Ensure XSS-safety for the current text format/editor. $filtered = editor_filter_xss($original, $format); if ($filtered !== FALSE) { $element['value']['#value'] = $filtered; } // Only when the user has access to multiple text formats, we must add data- // attributes for the original value and change tracking, because they are // only necessary when the end user can switch between text formats/editors. if ($element['format']['format']['#access']) { $element['value']['#attributes']['data-editor-value-is-changed'] = 'false'; $element['value']['#attributes']['data-editor-value-original'] = $original; } } return $element; }
/** * {@inheritdoc} */ protected function init(FormStateInterface $form_state) { parent::init($form_state); $this->entityType = $this->entityManager->getDefinition($this->entity->getEntityTypeId()); }
/** * {@inheritdoc} */ protected function init(array &$form_state) { parent::init($form_state); $this->entityType = $this->entityManager->getDefinition($this->entity->getEntityTypeId()); }
/** * Constructs a SettingsForm object. */ public function __construct(ConfigFactory $config_factory, ContextInterface $context, PluginManagerInterface $manager) { parent::__construct($config_factory, $context); $definition = $manager->getDefinition('fullcalendar_options'); $this->options = call_user_func(array($definition['class'], 'optionsList')); }