29
Mastering Views Andrey Yurtaev

Андрей Юртаев - Mastering Views

Embed Size (px)

Citation preview

Page 1: Андрей Юртаев - Mastering Views

Mastering Views

Andrey Yurtaev

Page 2: Андрей Юртаев - Mastering Views

Session plan

Interface overview:

● Most of UI elements

Examples:

● Agregation● Contextual filters● Theming● Admin pages● Overriding pages output

Sorry, no cats :(

Page 3: Андрей Юртаев - Mastering Views

Lets go

Page 4: Андрей Юртаев - Mastering Views

Views data types

● Comments● Content● Content revisions● Files● Taxonomy terms● Users

● D7: Theme engine● D8: Custom block● D8: Custom block revisions● D8: Log entries

Page 5: Андрей Юртаев - Mastering Views

Views UI

Page 6: Андрей Юртаев - Mastering Views

Views Displays

● Attachment● Block● Feed● Page

● D8: Embed● D8: Entity reference

Page 7: Андрей Юртаев - Mastering Views

Format and Show

Format:

● Grid● HTML List● Table● Unformatted list● D7: Jump menu

Show:

● Content● Fields● D8: Search results

Important thing: Grouping field

Page 8: Андрей Юртаев - Mastering Views

Fields

Depends on data type

Page 9: Андрей Юртаев - Mastering Views

Filters

Important things:

● Exposed filters● Exposed form settings

Useful module: Better Exposed Filters

Page 10: Андрей Юртаев - Mastering Views

Sort

Page 11: Андрей Юртаев - Mastering Views

Display settings

Page:

● Path● Menu

Page 12: Андрей Юртаев - Mastering Views

Header, Footer and No results

Important things:

● Unfiltered text● View area● D8: Rendered entity● D7 module: Views block area

View with no results:

Filter: Nid = 0

Page 14: Андрей Юртаев - Mastering Views

Contextual filters

Page 15: Андрей Юртаев - Mastering Views

Relationships

Page 16: Андрей Юртаев - Mastering Views

Other

Important things:

● AJAX● Query settings:

○ Disable SQL rewriting○ Distinct

Page 17: Андрей Юртаев - Mastering Views

Views and Displays

Important things:

● Clone views● Export/Import views● Clone displays● Overriding displays

Translate views: Internationalization Views

Page 18: Андрей Юртаев - Mastering Views

Examples

Page 19: Андрей Юртаев - Mastering Views

Generated content

Taxonomy: Genres

Content type: Author

● Name (Title): Text● Bio (Body): Long text

Content type: Book

● Title: Text● Description (Body): Long text● Author (D7 module: Entity reference)● Genre: Term reference

Page 20: Андрей Юртаев - Mastering Views

Aggregation

View name: Books by genresData type: Content, BookDisplay: PageDisplay format: HTML list, fieldsUse aggregation: YesField: Genre, Group results togetherField: Genre, Count

Page 21: Андрей Юртаев - Mastering Views

Contextual filters

View name: Author infoData type: Content, BookDisplay: BlockDisplay format: unformatted list, fieldsField: Author, Rendered entityContextual filter: Node ID, Provide default value -

Content ID from URL

Place block Author info: Only for content type - Book

Page 22: Андрей Юртаев - Mastering Views

Replacement tokens in Header

Clone Taxonomy termDisplay format: unformatted list, fieldsFields: Title, BodyRelationship: GenreField: Term description, Exclude from displayHeader: Unfiltered text,

Use replacement tokens from the first row

Page 23: Андрей Юртаев - Mastering Views

Theming

View name: Books grid viewData type: Content, BookDisplay: PageDisplay format:

unformatted list,row class - col-xs-12 col-sm-6 col-md-4

Uncheck Add row classes

Add to theme: views-view--books-grid-view.tpl.php

- <div class="view-content">+ <div class="view-content row"> <?php print $rows; ?> </div>

Page 24: Андрей Юртаев - Mastering Views

Admin pages

View name: Books adminData type: Content, BookDisplay: PagePath: admin/content/booksDisplay format: tableMenu: Menu tab, ManagementField: Title, etc.Field: Draggableviews: ContentField: Draggableviews: WeightSort criteria: Draggableviews: Weight

Extra module:DraggableViews

Useful modules:● Views Bulk Operations● Commerce Backoffice

Page 25: Андрей Юртаев - Mastering Views

Overriding default page output by View

For texonomy term pages:Path: taxonomy/term/%Contextual filter: tid, Provide default value -Taxonomy term ID from URL

Or module Taxonomy display

For user pages:Path: user/%Contextual filter: uid, Provide default value - User ID from URL

Page 26: Андрей Юртаев - Mastering Views

Overriding node output by View

View name: BookDisplay: PagePath: does not meter,

something like book/%Contextual filter: nid,

Provide default value - Content ID from URL,Override title - %1

Add to theme:node--book.tpl.php

- print render($content);+ print views_embed_view('book', 'page', $node->nid);

Page 27: Андрей Юртаев - Mastering Views

Overriding node output by View page 2

Field: Body, Exclude from displayField: Author, Exclude from displayField: Custom text

<div class="row"> <div class="col-xs-12 col-sm-8">[body]</div> <div class="col-xs-12 col-sm-4">[field_author]</div></div>

Page 28: Андрей Юртаев - Mastering Views

Summary

Views is great tool for:

● Node layout (instead Display Suite)● Page layout (instead Panels)● Awesome search (with Search API)● Products catalog (with Drupal Commerce)● DrupalCamp site :)

Page 29: Андрей Юртаев - Mastering Views

Thank You!Questions?

Gold sponsorWith support Silver sponsors