Mighty Morphing View Modes

twodotcuddlyInternet και Εφαρμογές Web

4 Δεκ 2013 (πριν από 3 χρόνια και 6 μήνες)

98 εμφανίσεις

Mighty Morphing
View Modes
Aaron Manire
Senior Developer
Isovera
What we’ll cover
What we’ll cover

An introduction/refresher on view modes
What we’ll cover

An introduction/refresher on view modes

A look at how some entities are using view
modes
What we’ll cover

An introduction/refresher on view modes

A look at how some entities are using view
modes

Walk through a couple of case studies
What we’ll cover

An introduction/refresher on view modes

A look at how some entities are using view
modes

Walk through a couple of case studies

No power rangers
Full content
Teaser
RSS
Search index
Search result
Default
What are view modes?
What are view modes?
A way to chunk and organize the display of
content into reusable elements
Groupings for fields and their display settings
Structure

Content
Types
Structure

Content
Types
Teaser out of the box
View modes enabled
Comment view modes
Drupal 6

Called ‘build modes’

Bundled with CCK
Why view modes rock!

Unified, consolidated interface

Help keep config and templates DRY

Lightweight, built into core

Available for all entities

Site builder/admin-friendly

Elegant
Respect
View Modes: The Many Faces of Your Content
by Tim Cosgrove
http://denver2012.drupal.org/program/sessions/
view-modes-many-faces-your-content
Core Entities

Comments

Nodes

Taxonomy

Users
Adding custom view
modes

Entity View Modes module

Display Suite

Custom code
Entity View Modes
drupal.org/project/entity_view_mode
Entity View Modes
module
Entity View Modes
module
Entity View Modes
module
Entity View Modes
module
Entity View Modes
module
Entity View Modes
module
Entity View Modes
module
Entity View Modes
module
Display Suite
drupal.org/project/ds
Display Suite
Display Suite
Custom code
<?php
function
hook_entity_info_alter
(&
$entity_info
){
 
$entity_info
[
'node'
][
'view modes'
][
'thumbnail'
] = array(
   
'label'
=>
t
(
'Thumbnail'
),
   
'custom settings'
=>
TRUE
,
  );
}
Case Studies

Sibling content

Repeated elements

Node reference

Embedding views displays

Cross-channel publishing
Sibling content
View mode code
<?php
function
usowc_core_entity_info_alter
(&
$entity_info
){
 
$entity_info
[
'node'
][
'view modes'
][
'extended'
] = array(
   
'label'
=>
t
(
'Extended'
),
   
'custom settings'
=>
TRUE
,
  );
}
Repeated Elements
Node Reference
Embedding Views
Displays
Add the field
<?php
function
hook_extra_fields
(){
 
$extra
[
'node'
][
'newsletter'
][
'display'
] = array(
   
'newsletter_faq'
=> array(

'label'
=>
t
(
'Newsletter FAQ'
),
   
'description'
=>
t
(
'Frequently Asked Questions'
),

'weight'
=>
0
,
),
  );
return $extra;
}
Render the field
<?php
function
hook_node_view
(
$node, $view_mode
){
switch(
$node->type
) {
case
'newsletter'
:

$node->content
[
'newsletter_faq'
] = array(
   
'#markup'
=> render_newsletter_faq()
  );
break;
}
}
function
render_newsletter_faq
(){

$view
= views_get_view(
'faq'
,
'block'
);

$output
=
'<h2>'
.
$view->get_title()

.
'</h2>'
;

$output
.=
$view->preview
(
'block'
, array());
return
$output;
}
Cross-Channel
Publishing
Contrib View Modes

Print

Diff

Token
Contrib Entities

Bean

Commerce

Entity Forms

Messaging

Organic Groups

And more…
Commerce
view modes
Entity
View modes
Product
Admin display
Order

Administrator

Customer
Line Item
Display
Customer

Administrator

Customer

Addressbook
Entity Forms
view
modes

Full content

Email

Confirmation

Downloads

Submissions Table
hook_entity_view_mode_alter()

Introduced in Drupal 7.17

Allow modules to change view modes on
display

drupal.org/node/1833086
Coming in Drupal 8
View modes will be configuration entities
(yml files) stored in config system
drupal.org/node/2012144
Blocks have view
modes

Custom blocks are entities

Block types and field displays

Full content
view mode by default
In-place Editing
Further reading
Simplify Complementary Content with View Mode Pages
https://www.isovera.com/blog/simplify-complementary-content-view-mode-pages
Drupal 7 custom node view modes
http://www.wunderkraut.com/blog/drupal-7-custom-node-view-modes/2010-12-20
How to Code a Custom Drupal Field Formatter for an Existing Field
http://www.paulbooker.co.uk/drupal-development-services/article/how-code-
custom-drupal-field-formatter-existing-field