/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = array(); $breadcrumb[] = $this->l($this->t('Home'), '<front>'); $entity = $this->entityManager->getStorage($route_match->getParameter('entity_type'))->load($route_match->getParameter('entity_id')); $breadcrumb[] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo()); return $breadcrumb; }
/** * Overrides \Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, array &$form_state) { $block_type = $this->entity; $status = $block_type->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); watchdog('block_content', 'Custom block type %label has been updated.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link); } else { drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label()))); watchdog('block_content', 'Custom block type %label has been added.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link); } $form_state['redirect_route']['route_name'] = 'block_content.type_list'; }
/** * {@inheritdoc} */ public function save(array $form, array &$form_state) { $comment_type = $this->entity; $status = $comment_type->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Comment type %label has been updated.', array('%label' => $comment_type->label()))); $this->logger->notice('Comment type %label has been updated.', array('%label' => $comment_type->label(), 'link' => $edit_link)); } else { drupal_set_message(t('Comment type %label has been added.', array('%label' => $comment_type->label()))); $this->logger->notice('Comment type %label has been added.', array('%label' => $comment_type->label(), 'link' => $edit_link)); } $form_state['redirect_route']['route_name'] = 'comment.type_list'; }
/** * Overrides Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, FormStateInterface $form_state) { $newsletter = $this->entity; $status = $newsletter->save(); $edit_link = \Drupal::linkGenerator()->generate($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Newsletter %label has been updated.', array('%label' => $newsletter->label()))); \Drupal::logger('simplenews')->notice('Newsletter %label has been updated.', array('%label' => $newsletter->label(), 'link' => $edit_link)); } else { drupal_set_message(t('Newsletter %label has been added.', array('%label' => $newsletter->label()))); \Drupal::logger('simplenews')->notice('Newsletter %label has been added.', array('%label' => $newsletter->label(), 'link' => $edit_link)); } $form_state->setRedirect('simplenews.newsletter_list'); }
/** * Overrides \Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, FormStateInterface $form_state) { $block_type = $this->entity; $status = $block_type->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); $logger = $this->logger('block_content'); if ($status == SAVED_UPDATED) { drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); $logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link)); } else { drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label()))); $logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link)); } $form_state->setRedirect('block_content.type_list'); }
/** * {@inheritdoc} */ public function save(array $form, array &$form_state) { $entity = $this->entity; // Prevent leading and trailing spaces in role names. $entity->set('label', trim($entity->label())); $status = $entity->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, $edit_link); } else { drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, $edit_link); } $form_state['redirect_route']['route_name'] = 'user.role_list'; }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; // Prevent leading and trailing spaces in role names. $entity->set('label', trim($entity->label())); $status = $entity->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); $this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link)); } else { drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); $this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link)); } $form_state->setRedirect('user.role_list'); }
/** * {@inheritdoc} */ public function save(array $form, array &$form_state) { $category = $this->entity; $status = $category->save(); $contact_settings = $this->config('contact.settings'); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('Category %label has been updated.', array('%label' => $category->label()))); watchdog('contact', 'Category %label has been updated.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link); } else { drupal_set_message($this->t('Category %label has been added.', array('%label' => $category->label()))); watchdog('contact', 'Category %label has been added.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link); } // Update the default category. if ($form_state['values']['selected']) { $contact_settings->set('default_category', $category->id())->save(); } elseif ($contact_settings->get('default_category') == $category->id()) { $contact_settings->set('default_category', NULL)->save(); } $form_state['redirect_route']['route_name'] = 'contact.category_list'; }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $category = $this->entity; $status = $category->save(); $contact_settings = $this->config('contact.settings'); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('Category %label has been updated.', array('%label' => $category->label()))); $this->logger('contact')->notice('Category %label has been updated.', array('%label' => $category->label(), 'link' => $edit_link)); } else { drupal_set_message($this->t('Category %label has been added.', array('%label' => $category->label()))); $this->logger('contact')->notice('Category %label has been added.', array('%label' => $category->label(), 'link' => $edit_link)); } // Update the default category. if ($form_state['values']['selected']) { $contact_settings->set('default_category', $category->id())->save(); } elseif ($contact_settings->get('default_category') == $category->id()) { $contact_settings->set('default_category', NULL)->save(); } $form_state->setRedirect('contact.category_list'); }
/** * {@inheritdoc} */ public function save(array $form, array &$form_state) { $menu = $this->entity; if (!$menu->isNew() || $menu->isLocked()) { $this->submitOverviewForm($form, $form_state); } $status = $menu->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Menu %label has been updated.', array('%label' => $menu->label()))); watchdog('menu', 'Menu %label has been updated.', array('%label' => $menu->label()), WATCHDOG_NOTICE, $edit_link); } else { drupal_set_message(t('Menu %label has been added.', array('%label' => $menu->label()))); watchdog('menu', 'Menu %label has been added.', array('%label' => $menu->label()), WATCHDOG_NOTICE, $edit_link); } $form_state['redirect_route'] = $this->entity->urlInfo('edit-form'); }
/** * Gets the link generator. * * @return \Drupal\Core\Utility\LinkGeneratorInterface */ protected function linkGenerator() { if (!isset($this->linkGenerator)) { $this->linkGenerator = \Drupal::linkGenerator(); } return $this->linkGenerator; }
/** * {@inheritdoc} */ public function buildRow(EntityInterface $field) { if ($field->locked) { $row['class'] = array('menu-disabled'); $row['data']['id'] = t('@field_name (Locked)', array('@field_name' => $field->name)); } else { $row['data']['id'] = $field->name; } $field_type = $this->fieldTypes[$field->type]; $row['data']['type'] = t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider'])); $usage = array(); foreach ($field->getBundles() as $bundle) { if ($route_info = FieldUI::getOverviewRouteInfo($field->entity_type, $bundle)) { $usage[] = \Drupal::linkGenerator()->generateFromUrl($this->bundles[$field->entity_type][$bundle]['label'], $route_info); } else { $usage[] = $this->bundles[$field->entity_type][$bundle]['label']; } } $usage_escaped = ''; $separator = ''; foreach ($usage as $usage_item) { $usage_escaped .= $separator . SafeMarkup::escape($usage_item); $separator = ', '; } $row['data']['usage'] = SafeMarkup::set($usage_escaped); return $row; }
/** * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { $row['type'] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo()); $row['description'] = Xss::filterAdmin($entity->description); return $row + parent::buildRow($entity); }
/** * Tests the linkGenerator() method. * * @covers ::linkGenerator */ public function testLinkGenerator() { $this->setMockContainerService('link_generator'); $this->assertNotNull(\Drupal::linkGenerator()); }
/** * {@inheritdoc} */ public function save(array $form, array &$form_state) { $vocabulary = $this->entity; // Prevent leading and trailing spaces in vocabulary names. $vocabulary->name = trim($vocabulary->name); $status = $vocabulary->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); switch ($status) { case SAVED_NEW: drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, $edit_link); $form_state['redirect_route'] = $vocabulary->urlInfo('overview-form'); break; case SAVED_UPDATED: drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); watchdog('taxonomy', 'Updated vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, $edit_link); $form_state['redirect_route']['route_name'] = 'taxonomy.vocabulary_list'; break; } $form_state['values']['vid'] = $vocabulary->id(); $form_state['vid'] = $vocabulary->id(); }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $vocabulary = $this->entity; // Prevent leading and trailing spaces in vocabulary names. $vocabulary->name = trim($vocabulary->name); $status = $vocabulary->save(); $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); switch ($status) { case SAVED_NEW: drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); $form_state->setRedirectUrl($vocabulary->urlInfo('overview-form')); break; case SAVED_UPDATED: drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); $form_state->setRedirect('taxonomy.vocabulary_list'); break; } $form_state['values']['vid'] = $vocabulary->id(); $form_state['vid'] = $vocabulary->id(); }
/** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { $active = \Drupal::linkGenerator()->getActive(); $language_url = \Drupal::languageManager()->getLanguage(Language::TYPE_URL); $unique_id = uniqid(); $module_path = drupal_get_path('module', 'lang_dropdown'); $options = $js_settings = $hidden_elements = array(); $selected_option_language_icon = $language_selected = $language_session_selected = ''; $form['lang_dropdown_type'] = array('#type' => 'value', '#default_value' => $this->type); $form['lang_dropdown_tohome'] = array('#type' => 'value', '#default_value' => $this->settings['tohome']); $language_objects = language_list(); // Support Domain access if ($domain_locale_exists = module_exists('domain_locale')) { global $_domain; $domain_languages = domain_locale_lookup($_domain['domain_id']); } // Now we iterate on $languages to build the needed options for the select element. foreach ($this->languages as $lang_code => $lang_options) { // The language is not enabled on this domain if ($domain_locale_exists && !array_key_exists($lang_code, $domain_languages)) { continue; } // There is no translation for this language and not all languages are shown if (in_array('locale-untranslated', $lang_options['attributes']['class']) && !$this->settings['showall']) { continue; } // Build the options in an assosiative array, so it will be ready for #options in select form element. switch ($this->settings['display']) { case LANGDROPDOWN_DISPLAY_TRANSLATED: $options += array($lang_code => t($language_objects[$lang_code]->name)); break; case LANGDROPDOWN_DISPLAY_NATIVE: $options += array($lang_code => t($language_objects[$lang_code]->name, array(), array('langcode' => $lang_code))); break; case LANGDROPDOWN_DISPLAY_LANGCODE: $options += array($lang_code => $lang_code); break; default: $options += array($lang_code => t($language_objects[$lang_code]->name)); break; } // Identify selected language if (isset($lang_options['route_name'])) { $variables = array('options' => array()); if (!empty($link['language'])) { $variables['options']['language'] = $link['language']; } if ($lang_options['route_name'] == $active['route_name'] && (empty($variables['options']['language']) || $variables['options']['language']->id == $active['language']) && $lang_options['route_parameters'] == $active['parameters']) { $language_selected = $lang_code; } } elseif (isset($lang_options['href'])) { $is_current_path = $lang_options['href'] == current_path() || $lang_options['href'] == '<front>' && drupal_is_front_page(); $is_current_language = empty($lang_options['language']) || $lang_options['language']->id == $language_url->id; if ($is_current_path && $is_current_language) { $language_selected = $lang_code; } } // Identify if session negotiation had set session-active class // the trim is needed because of a bug in locale.inc, drupal version <7.24 at least if (in_array('session-active', array_map('trim', $lang_options['attributes']['class']))) { $language_session_selected = $lang_code; } // Now we build our hidden form inputs to handle the redirections. $href = isset($lang_options['href']) && $this->settings['tohome'] == 0 ? $lang_options['href'] : '<front>'; if (!isset($lang_options['query'])) { $lang_options['query'] = drupal_get_query_parameters(); } $hidden_elements[$lang_code] = array('#type' => 'hidden', '#default_value' => url($href, $lang_options)); // Handle flags with Language icons module using JS widget. if (module_exists('languageicons') && $this->settings['widget']) { $languageicons_path = variable_get('languageicons_path', drupal_get_path('module', 'languageicons') . '/flags/*.png'); $js_settings['languageicons'][$lang_code] = file_create_url(str_replace('*', $lang_code, $languageicons_path)); } } // If session-active is set that's the selected language otherwise rely on $language_selected $selected_option = $language_session_selected == '' ? $language_selected : $language_session_selected; // Icon for the selected language if (module_exists('languageicons') && !$this->settings['widget']) { $selected_option_language_icon = theme('languageicons_icon', array('language' => (object) array('language' => $selected_option), 'title' => $language_names[$selected_option])); } // Add required files and settings for JS widget. if ($this->settings['widget'] == LANGDROPDOWN_MSDROPDOWN) { drupal_add_library('lang_dropdown', 'msdropdown'); $js_settings += array('widget' => 'msdropdown', 'visibleRows' => $this->settings['msdropdown']['visible_rows'], 'roundedCorner' => $this->settings['msdropdown']['rounded'], 'animStyle' => $this->settings['msdropdown']['animation'], 'event' => $this->settings['msdropdown']['event']); $selected_skin = $this->settings['msdropdown']['skin']; if ($selected_skin == 'custom') { $custom_skin = check_plain($this->settings['msdropdown']['custom_skin']); drupal_add_css(_lang_dropdown_get_msdropdown_path() . '/css/msdropdown/' . $custom_skin . '.css'); $js_settings += array('mainCSS' => $custom_skin); } else { $skins = _lang_dropdown_get_msdropdown_skins(); $skin_data = $skins[$selected_skin]; drupal_add_css($skin_data['file']); $js_settings += array('mainCSS' => $skin_data['mainCSS']); } drupal_add_js(array('lang_dropdown' => array($unique_id => array('jsWidget' => $js_settings))), 'setting'); } else { if ($this->settings['widget'] == LANGDROPDOWN_CHOSEN) { drupal_add_library('lang_dropdown', 'chosen'); $js_settings += array('widget' => 'chosen', 'disable_search' => $this->settings['chosen']['disable_search'], 'no_results_text' => $this->settings['chosen']['no_results_text']); drupal_add_js(array('lang_dropdown' => array($unique_id => array('jsWidget' => $js_settings))), 'setting'); } else { if ($this->settings['widget'] == LANGDROPDOWN_DDSLICK) { drupal_add_library('lang_dropdown', 'ddslick'); $selected_skin = $this->settings['ddslick']['skin']; if ($selected_skin == 'custom') { $custom_skin = check_plain($this->settings['ddslick']['custom_skin']); drupal_add_css(_lang_dropdown_get_ddslick_path() . '/' . $custom_skin . '.css'); $ddsSkin = $custom_skin; } else { $skins = _lang_dropdown_get_ddslick_skins(); $skin_data = $skins[$selected_skin]; drupal_add_css($skin_data['file']); $ddsSkin = $selected_skin; } $js_settings += array('widget' => 'ddslick', 'width' => $this->settings['width'], 'height' => $this->settings['ddslick']['ddslick_height'], 'showSelectedHTML' => $this->settings['ddslick']['showSelectedHTML'], 'imagePosition' => $this->settings['ddslick']['imagePosition']); drupal_add_js(array('lang_dropdown' => array($unique_id => array('jsWidget' => $js_settings))), 'setting'); } } } $this->settings['languageicons']['flag_position'] ? $flag_position = '#suffix' : ($flag_position = '#prefix'); // Now we build the $form array. $form['lang_dropdown_select'] = array('#type' => 'select', '#default_value' => isset($selected_option) ? $selected_option : key($options), '#options' => $options, '#attributes' => array('style' => 'width:' . $this->settings['width'] . 'px', 'class' => array('lang-dropdown-select-element'), 'id' => 'lang-dropdown-select-' . $unique_id), '#attached' => array('js' => array($module_path . '/js/lang_dropdown.js'), 'css' => $this->settings['widget'] ? array() : array($module_path . '/css/lang_dropdown.css'))); if (empty($hidden_elements)) { return array(); } $form += $hidden_elements; if (module_exists('languageicons')) { $form['lang_dropdown_select'][$flag_position] = $selected_option_language_icon; } $form['#attributes']['class'] = array('lang_dropdown_form', $this->type); $form['#attributes']['id'] = 'lang_dropdown_form_' . $unique_id; if ($this->settings['widget'] == LANGDROPDOWN_DDSLICK) { $form['#attributes']['class'][] = $ddsSkin; } $form['submit'] = array('#type' => 'submit', '#value' => t('Go'), '#prefix' => "<noscript><div>\n", '#suffix' => "\n</div></noscript>"); return $form; }