namespace Drupal\views_ui;
use Drupal\Component\Utility\Html;
-use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\Core\Url;
-use Drupal\user\SharedTempStoreFactory;
+use Drupal\Core\TempStore\SharedTempStoreFactory;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
/**
* Form controller for the Views edit form.
+ *
+ * @internal
*/
class ViewEditForm extends ViewFormBase {
/**
* The views temp store.
*
- * @var \Drupal\user\SharedTempStore
+ * @var \Drupal\Core\TempStore\SharedTempStore
*/
protected $tempStore;
/**
* Constructs a new ViewEditForm object.
*
- * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
+ * @param \Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory
* The factory for the temp store object.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack object.
*/
public static function create(ContainerInterface $container) {
return new static(
- $container->get('user.shared_tempstore'),
+ $container->get('tempstore.shared'),
$container->get('request_stack'),
$container->get('date.formatter'),
$container->get('element_info')
'#account' => $this->entityManager->getStorage('user')->load($view->lock->owner),
];
$lock_message_substitutions = [
- '@user' => drupal_render($username),
+ '@user' => \Drupal::service('renderer')->render($username),
'@age' => $this->dateFormatter->formatTimeDiffSince($view->lock->updated),
':url' => $view->url('break-lock-form'),
];
],
];
-
$form['displays']['top'] = $this->renderDisplayTop($view);
// The rest requires a display to be selected.
// options.
$display_handler = $executable->displayHandlers->get($id);
if ($attachments = $display_handler->getAttachedDisplays()) {
- foreach ($attachments as $attachment ) {
+ foreach ($attachments as $attachment) {
$attached_options = $executable->displayHandlers->get($attachment)->getOption('displays');
unset($attached_options[$id]);
$executable->displayHandlers->get($attachment)->setOption('displays', $attached_options);
// Rename display ids if needed.
foreach ($executable->displayHandlers as $id => $display) {
- if (!empty($display->display['new_id']) && empty($display->display['deleted'])) {
+ if (!empty($display->display['new_id']) && $display->display['new_id'] !== $display->display['id'] && empty($display->display['deleted'])) {
$new_id = $display->display['new_id'];
$display->display['id'] = $new_id;
unset($display->display['new_id']);
'display_id' => $new_id,
]);
}
+ elseif (isset($display->display['new_id'])) {
+ unset($display->display['new_id']);
+ }
}
$view->set('display', $displays);
$view->save();
- drupal_set_message($this->t('The view %name has been saved.', ['%name' => $view->label()]));
+ $this->messenger()->addStatus($this->t('The view %name has been saved.', ['%name' => $view->label()]));
// Remove this view from cache so we can edit it properly.
$this->tempStore->delete($view->id());
// path.
elseif ($view->status() && $view->getExecutable()->displayHandlers->get($display['id'])->hasPath()) {
$path = $view->getExecutable()->displayHandlers->get($display['id'])->getPath();
+
if ($path && (strpos($path, '%') === FALSE)) {
- if (!parse_url($path, PHP_URL_SCHEME)) {
- // @todo Views should expect and store a leading /. See:
- // https://www.drupal.org/node/2423913
- $url = Url::fromUserInput('/' . ltrim($path, '/'));
+ // Wrap this in a try/catch as trying to generate links to some
+ // routes may throw a NotAcceptableHttpException if they do not
+ // respond to HTML, such as RESTExports.
+ try {
+ if (!parse_url($path, PHP_URL_SCHEME)) {
+ // @todo Views should expect and store a leading /. See:
+ // https://www.drupal.org/node/2423913
+ $url = Url::fromUserInput('/' . ltrim($path, '/'));
+ }
+ else {
+ $url = Url::fromUri("base:$path");
+ }
}
- else {
- $url = Url::fromUri("base:$path");
+ catch (NotAcceptableHttpException $e) {
+ $url = '/' . $path;
}
+
$build['top']['actions']['path'] = [
'#type' => 'link',
'#title' => $this->t('View @display_title', ['@display_title' => $display_title]),
$build['fields'][$id]['#class'][] = Html::cleanCssIdentifier($display['id'] . '-' . $type . '-' . $id);
if ($executable->display_handler->useGroupBy() && $handler->usesGroupBy()) {
- $build['fields'][$id]['#settings_links'][] = $this->l(SafeMarkup::format('<span class="label">@text</span>', ['@text' => $this->t('Aggregation settings')]), new Url('views_ui.form_handler_group', [
+ $build['fields'][$id]['#settings_links'][] = $this->l(new FormattableMarkup('<span class="label">@text</span>', ['@text' => $this->t('Aggregation settings')]), new Url('views_ui.form_handler_group', [
'js' => 'nojs',
'view' => $view->id(),
'display_id' => $display['id'],
}
if ($handler->hasExtraOptions()) {
- $build['fields'][$id]['#settings_links'][] = $this->l(SafeMarkup::format('<span class="label">@text</span>', ['@text' => $this->t('Settings')]), new Url('views_ui.form_handler_extra', [
+ $build['fields'][$id]['#settings_links'][] = $this->l(new FormattableMarkup('<span class="label">@text</span>', ['@text' => $this->t('Settings')]), new Url('views_ui.form_handler_extra', [
'js' => 'nojs',
'view' => $view->id(),
'display_id' => $display['id'],
foreach ($contents as $key => $pid) {
if ($key != $last) {
$operator = $group_info['groups'][$gid] == 'OR' ? $this->t('OR') : $this->t('AND');
- $store[$pid]['#link'] = SafeMarkup::format('@link <span>@operator</span>', ['@link' => $store[$pid]['#link'], '@operator' => $operator]);
+ $store[$pid]['#link'] = new FormattableMarkup('@link <span>@operator</span>', ['@link' => $store[$pid]['#link'], '@operator' => $operator]);
}
$build['fields'][$pid] = $store[$pid];
}