Editing the default admin interfaces

With the addition of Views in Drupal core, many of the administrative interfaces are powered by Views. This allows customization of default admin interfaces to enhance site management and content authoring experiences.

Note

In Drupal 7 and 6 there was the administrative Views module, which provided a way to override administrative pages with Views. This module is no longer required, as the functionality comes with Drupal core out of the box!

In this recipe we will modify the default content overview form that is used to find and edit content. We will add the ability to filter content by the user who authored it.

How to do it…

  1. Visit Structure and then Views. This will bring you to the administrative overview of all existing views.
  2. From the Enabled section, select the Edit option for the Content view. This is the view displayed on /admin/content when managing content.
  3. In order to filter by the content author, we must add a FILTER CRITERIA to our view, which we will expose the following for users to modify:
    How to do it…
  4. Click on Add to add a new filter. In the search text box type Authored by to search the available options. Select Content: Authored by and click Apply (all displays):
    How to do it…
  5. Check Expose this filter to visitors, to allow them to change it via checkbox. This will allow users to modify the data for the filter.
  6. You may modify the Label and add a Description to improve the usability of the filter option for your use case.
  7. Click on Apply (all displays) once more to finish configuring the filter. It will now show up in the list as filter criteria active. You will also see the new filter in the preview below the form.
  8. Click on Save to commit all changes to the view.
  9. View /admin/content and you will have your filter. Content editors will be able to search for content authored by a user through autocompleted username searches:
    How to do it…

How it works…

When a view is created that has a path matching an existing route, it will override it and present itself. That is how the /admin/content and other administrative pages are able to be powered by Views.

Note

If you were to disable the Views module you can still manage content and users. The default forms are tables that do not provide filters or other extra features.

Drupal uses the overridden route and uses Views to render the page. From that point on the page is handled like any other Views page would be rendered.

There's more…

We will dive into additional features available through Views that can enhance the way you use Views and present them on your Drupal site.

Exposed versus non-exposed

Filters allow you to narrow the scope of the data displayed in a view. Filters can either be exposed or not; by default a filter is not exposed. An example would be using the Content: Publishing status set to Yes (published) to ensure a view always contains published content. This is an item you would configure for displaying content to site visitors. However, if it were for an administrative display, you may want to expose that filter. This way content editors have the ability to view, easily, what content has not been published yet or has been unpublished.

All filter and sort criteria can be marked as exposed.

Filter identifiers

Exposed filters work by parsing query parameters in the URL. For instance, on the content management form, changing the Type filter will add type=Article amongst others to the current URL.

With this recipe the author filter would show up as uid in the URL. Exposed filters have a Filter identifier option that can change the URL component.

Filter identifiers

This could be changed to author or some other value to enhance the user experience behind the URL, or mask the Drupal-ness of it.

Overriding routes with Views

Views is able to replace administrative pages with enhanced versions due to the way the route and module system works in Drupal. Modules are executed in order of the module's weight or alphabetical order if weights are the same. Naturally, in the English alphabet, the letter V comes towards the end of the alphabet. That means any route that Views provides will be added towards the end of the route discovery cycle.

If a view is created and it provides a route path, it will override any that exist on that path. There is not a collision checking mechanism (and there was not in Views before merging into Drupal core) that prevents this.

This allows you to easily customize most existing routes. But, beware that you could easily have conflicting routes and Views will normally override the other.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset