예제 #1
0
 /**
  * Tests the isLocked method.
  */
 public function testIsLocked()
 {
     $storage = $this->getMock('Drupal\\views\\Entity\\View', array(), array(array(), 'view'));
     $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->setConstructorArgs(array($storage))->getMock();
     $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $account->expects($this->exactly(2))->method('id')->will($this->returnValue(1));
     $container = new ContainerBuilder();
     $container->set('current_user', $account);
     \Drupal::setContainer($container);
     $view_ui = new ViewUI($storage, $executable);
     // A view_ui without a lock object is not locked.
     $this->assertFalse($view_ui->isLocked());
     // Set the lock object with a different owner than the mocked account above.
     $lock = (object) array('owner' => 2, 'data' => array(), 'updated' => REQUEST_TIME);
     $view_ui->lock = $lock;
     $this->assertTrue($view_ui->isLocked());
     // Set a different lock object with the same object as the mocked account.
     $lock = (object) array('owner' => 1, 'data' => array(), 'updated' => REQUEST_TIME);
     $view_ui->lock = $lock;
     $this->assertFalse($view_ui->isLocked());
 }
예제 #2
0
 /**
  * Add information about a section to a display.
  */
 public function getFormBucket(ViewUI $view, $type, $display)
 {
     $executable = $view->getExecutable();
     $executable->setDisplay($display['id']);
     $executable->initStyle();
     $types = $executable->getHandlerTypes();
     $build = array('#theme_wrappers' => array('views_ui_display_tab_bucket'));
     $build['#overridden'] = FALSE;
     $build['#defaulted'] = FALSE;
     $build['#name'] = $type;
     $build['#title'] = $types[$type]['title'];
     $rearrange_url = Url::fromRoute('views_ui.form_rearrange', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type]);
     $class = 'icon compact rearrange';
     // Different types now have different rearrange forms, so we use this switch
     // to get the right one.
     switch ($type) {
         case 'filter':
             // The rearrange form for filters contains the and/or UI, so override
             // the used path.
             $rearrange_url = Url::fromRoute('views_ui.form_rearrange_filter', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id']]);
             // TODO: Add another class to have another symbol for filter rearrange.
             $class = 'icon compact rearrange';
             break;
         case 'field':
             // Fetch the style plugin info so we know whether to list fields or not.
             $style_plugin = $executable->style_plugin;
             $uses_fields = $style_plugin && $style_plugin->usesFields();
             if (!$uses_fields) {
                 $build['fields'][] = array('#markup' => $this->t('The selected style or row format does not use fields.'), '#theme_wrappers' => array('views_ui_container'), '#attributes' => array('class' => array('views-display-setting')));
                 return $build;
             }
             break;
         case 'header':
         case 'footer':
         case 'empty':
             if (!$executable->display_handler->usesAreas()) {
                 $build[$type][] = array('#markup' => $this->t('The selected display type does not use @type plugins', array('@type' => $type)), '#theme_wrappers' => array('views_ui_container'), '#attributes' => array('class' => array('views-display-setting')));
                 return $build;
             }
             break;
     }
     // Create an array of actions to pass to links template.
     $actions = array();
     $count_handlers = count($executable->display_handler->getHandlers($type));
     // Create the add text variable for the add action.
     $add_text = $this->t('Add <span class="visually-hidden">@type</span>', array('@type' => $types[$type]['ltitle']));
     $actions['add'] = array('title' => $add_text, 'url' => Url::fromRoute('views_ui.form_add_handler', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type]), 'attributes' => array('class' => array('icon compact add', 'views-ajax-link'), 'id' => 'views-add-' . $type));
     if ($count_handlers > 0) {
         // Create the rearrange text variable for the rearrange action.
         $rearrange_text = $type == 'filter' ? $this->t('And/Or Rearrange <span class="visually-hidden">filter criteria</span>') : $this->t('Rearrange <span class="visually-hidden">@type</span>', array('@type' => $types[$type]['ltitle']));
         $actions['rearrange'] = array('title' => $rearrange_text, 'url' => $rearrange_url, 'attributes' => array('class' => array($class, 'views-ajax-link'), 'id' => 'views-rearrange-' . $type));
     }
     // Render the array of links
     $build['#actions'] = array('#type' => 'dropbutton', '#links' => $actions, '#attributes' => array('class' => array('views-ui-settings-bucket-operations')));
     if (!$executable->display_handler->isDefaultDisplay()) {
         if (!$executable->display_handler->isDefaulted($types[$type]['plural'])) {
             $build['#overridden'] = TRUE;
         } else {
             $build['#defaulted'] = TRUE;
         }
     }
     static $relationships = NULL;
     if (!isset($relationships)) {
         // Get relationship labels.
         $relationships = array();
         foreach ($executable->display_handler->getHandlers('relationship') as $id => $handler) {
             $relationships[$id] = $handler->adminLabel();
         }
     }
     // Filters can now be grouped so we do a little bit extra:
     $groups = array();
     $grouping = FALSE;
     if ($type == 'filter') {
         $group_info = $executable->display_handler->getOption('filter_groups');
         // If there is only one group but it is using the "OR" filter, we still
         // treat it as a group for display purposes, since we want to display the
         // "OR" label next to items within the group.
         if (!empty($group_info['groups']) && (count($group_info['groups']) > 1 || current($group_info['groups']) == 'OR')) {
             $grouping = TRUE;
             $groups = array(0 => array());
         }
     }
     $build['fields'] = array();
     foreach ($executable->display_handler->getOption($types[$type]['plural']) as $id => $field) {
         // Build the option link for this handler ("Node: ID = article").
         $build['fields'][$id] = array();
         $build['fields'][$id]['#theme'] = 'views_ui_display_tab_setting';
         $handler = $executable->display_handler->getHandler($type, $id);
         if ($handler->broken()) {
             $build['fields'][$id]['#class'][] = 'broken';
             $field_name = $handler->adminLabel();
             $build['fields'][$id]['#link'] = $this->l($field_name, new Url('views_ui.form_handler', array('js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type, 'id' => $id), array('attributes' => array('class' => array('views-ajax-link')))));
             continue;
         }
         $field_name = $handler->adminLabel(TRUE);
         if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
             $field_name = '(' . $relationships[$field['relationship']] . ') ' . $field_name;
         }
         $description = Xss::filterAdmin($handler->adminSummary());
         $link_text = $field_name . (empty($description) ? '' : " ({$description})");
         $link_attributes = array('class' => array('views-ajax-link'));
         if (!empty($field['exclude'])) {
             $link_attributes['class'][] = 'views-field-excluded';
             // Add a [hidden] marker, if the field is excluded.
             $link_text .= ' [' . $this->t('hidden') . ']';
         }
         $build['fields'][$id]['#link'] = $this->l($link_text, new Url('views_ui.form_handler', array('js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type, 'id' => $id), array('attributes' => $link_attributes)));
         $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>', array('@text' => $this->t('Aggregation settings'))), new Url('views_ui.form_handler_group', array('js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type, 'id' => $id), array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Aggregation settings')))));
         }
         if ($handler->hasExtraOptions()) {
             $build['fields'][$id]['#settings_links'][] = $this->l(SafeMarkup::format('<span class="label">@text</span>', array('@text' => $this->t('Settings'))), new Url('views_ui.form_handler_extra', array('js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type, 'id' => $id), array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Settings')))));
         }
         if ($grouping) {
             $gid = $handler->options['group'];
             // Show in default group if the group does not exist.
             if (empty($group_info['groups'][$gid])) {
                 $gid = 0;
             }
             $groups[$gid][] = $id;
         }
     }
     // If using grouping, re-order fields so that they show up properly in the list.
     if ($type == 'filter' && $grouping) {
         $store = $build['fields'];
         $build['fields'] = array();
         foreach ($groups as $gid => $contents) {
             // Display an operator between each group.
             if (!empty($build['fields'])) {
                 $build['fields'][] = array('#theme' => 'views_ui_display_tab_setting', '#class' => array('views-group-text'), '#link' => $group_info['operator'] == 'OR' ? $this->t('OR') : $this->t('AND'));
             }
             // Display an operator between each pair of filters within the group.
             $keys = array_keys($contents);
             $last = end($keys);
             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]);
                 }
                 $build['fields'][$pid] = $store[$pid];
             }
         }
     }
     return $build;
 }
예제 #3
0
 /**
  * Returns the form to edit a view.
  *
  * @param \Drupal\views_ui\ViewUI $view
  *   The view to be edited.
  * @param string|null $display_id
  *   (optional) The display ID being edited. Defaults to NULL, which will load
  *   the first available display.
  *
  * @return array
  *   An array containing the Views edit and preview forms.
  */
 public function edit(ViewUI $view, $display_id = NULL)
 {
     $name = $view->label();
     $data = $this->viewsData->get($view->get('base_table'));
     if (isset($data['table']['base']['title'])) {
         $name .= ' (' . $data['table']['base']['title'] . ')';
     }
     $build['#title'] = $name;
     $build['edit'] = $this->entityFormBuilder()->getForm($view, 'edit', array('display_id' => $display_id));
     $build['preview'] = $this->entityFormBuilder()->getForm($view, 'preview', array('display_id' => $display_id));
     return $build;
 }
예제 #4
0
 /**
  * Tests serialization of the ViewUI object.
  */
 public function testSerialization()
 {
     // Set a container so the DependencySerializationTrait has it.
     $container = new ContainerBuilder();
     \Drupal::setContainer($container);
     $storage = new View([], 'view');
     $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->setConstructorArgs([$storage])->getMock();
     $storage->set('executable', $executable);
     $view_ui = new ViewUI($storage);
     // Make sure the executable is returned before serializing.
     $this->assertInstanceOf('Drupal\\views\\ViewExecutable', $view_ui->getExecutable());
     $serialized = serialize($view_ui);
     // Make sure the ViewExecutable class is not found in the serialized string.
     $this->assertSame(strpos($serialized, '"Drupal\\views\\ViewExecutable"'), FALSE);
     $unserialized = unserialize($serialized);
     $this->assertInstanceOf('Drupal\\views_ui\\ViewUI', $unserialized);
 }
예제 #5
0
 /**
  * Placeholder function for overriding $display['display_title'].
  *
  * @todo Remove this function once editing the display title is possible.
  */
 public function getDisplayLabel(ViewUI $view, $display_id, $check_changed = TRUE)
 {
     $display = $view->get('display');
     $title = $display_id == 'default' ? $this->t('Master') : $display[$display_id]['display_title'];
     $title = views_ui_truncate($title, 25);
     if ($check_changed && !empty($view->changed_display[$display_id])) {
         $changed = '*';
         $title = $title . $changed;
     }
     return $title;
 }