SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
# Views Plugins in Drupal 7 and Drupal 8 
● Michael Lenahan, Developer at erdfisch 
● http://drupalcamp.berlin/program/sessions/views­plugins­d7­and­d8
# Key Points 
● In D7, views is extensible through plugins 
● In D8, all of Drupal is extensible through plugins 
● In D7, Views is object­oriented 
● In D8, All of Drupal is object­oriented
# tutorial and documentation 
# Source: http://www.codem0nk3y.com/2012/04/what­bugs­me­about­modx­and­why/ 
cms­learning­curve/
Drupal 7 ­­­setup 
# enable views and views_ui 
drush en ­y 
views_ui 
# enable the frontpage view at: 
# admin/structure/views 
# set 'Default front page' to 'frontpage' at: 
# admin/config/system/site­information 
# add some content
Drupal 7 ­­­setup
# Drupal 7 
# Mummy, where do views plugins come from?
# Look in s/a/m/contrib/views/includes/plugins.inc 
# All the 'native' views plugins are declared there. 
/** 
* Implements hook_views_plugins(). 
*/ 
function views_views_plugins() { 
$plugins = array( 
// display, style, row, argument default, argument 
validator and access. 
● So we will also need to implement hook_views_plugins().
# drupal 7 
cd sites/all/modules/contrib/views/plugins && ls
class views_plugin_access_none extends views_plugin_access 
class views_plugin_access_perm extends views_plugin_access 
class views_plugin_access_role extends views_plugin_access
# using sublime text (ctrl p) 
# alternatively, use grep on the command line: 
grep ­rin 
'extends views_plugin' .
# Look in s/a/m/contrib/views/includes/plugins.inc 
# Views declares its own plugins by implementing 
hook_views_plugins(). 
function views_views_plugins() { 
$plugins = array( 
// display, style, row, argument default, argument 
validator and access. 
'access' => array( 
'none' => array( 
'title' => t('None'), 
'help' => t('Will be available to all users.'), 
'handler' => 'views_plugin_access_none', 
'help topic' => 'access­none', 
),
# Let's create a D7 custom views access plugin
# Let's create a D7 custom views access plugin 
mkdir ­p 
sites/all/modules/custom/my_views_plugins 
cd sites/all/modules/custom/my_views_plugins 
# Create a file named my_views_plugins.info: 
name = My Views Plugins 
description = Some views plugins examples. 
core = 7.x 
# Create an empty file named my_views_plugins.module.
# Enable our empty D7 module by browsing to: 
admin/modules
# In D7, we need to tell Drupal we are using views. 
# Copy the following text into my_views_plugins.module: 
<?php 
/** 
* Implements hook_views_api(). 
*/ 
function my_views_plugin_views_api() { 
return array( 
'api' => '3', 
); 
}
# In D7, we need to implement hook_views_plugins(). 
# Create the following file: 
s/a/m/custom/my_views_plugins/my_views_plugin.views.inc 
function my_views_plugin_views_plugins() { 
$plugins = array(); 
// Tip: copy from: sites/all/modules/contrib/views/includes/plugins.inc 
$plugins['access'] = array( 
'time' => array( 
'title' => t('Time'), 
'help' => t('Access will be granted according to time of day.'), 
'handler' => 'views_plugin_access_time', 
), 
); 
return $plugins; 
}
# We still need to tell D7 about the .inc file. 
# Add the files[] line to my_views_plugin.info: 
name = My Views Plugins 
description = Some views plugins examples. 
core = 7.x 
files[] = plugins/views_plugin_access_time.inc
# Clear the cache (drush cc views or 
admin/config/development/performance) 
# Reload: admin/structure/views/view/frontpage/edit
# Now write the actual plugin class: 
# my_views_plugins/plugins/views_plugin_access_time.inc 
class views_plugin_access_time extends 
views_plugin_access { 
// Override the base class methods. 
function access($account) { 
return _my_views_plugin_access(); 
} 
function get_access_callback() { 
return array('_my_views_plugin_access'); 
}
# my_views_plugin.module 
function _my_views_plugin_access() { 
$date = new DateTime('now'); 
$hour = $date­> 
format('H'); 
if ($hour > 22) { 
// The children are in bed. 
return TRUE; 
} 
return FALSE; 
}
# This Demo is brought to you by Funny Cat
# Views Plugins in Drupal 8 
mkdir ­p 
modules/custom/my_views_plugins 
cd modules/custom/my_views_plugins 
# Create a file named my_views_plugins.info.yml 
name: My Views Plugins 
type: module 
description: Some views plugins examples. 
core: 8.x 
# Create an empty my_views_plugins.module file 
<?php
# Enable our empty D8 module by browsing to: 
admin/modules
# In Drupal 8, views access plugins are to be found in a 
predictable location. 
# This means that they can be easily discovered! 
core/modules/user/src/Plugin/views/access/Permission.php 
core/modules/user/src/Plugin/views/access/Role.php 
core/modules/views/src/Plugin/views/access/None.php 
● So, let's create the same directory structure … 
(cd to your drupal­8 
root) 
mkdir ­p 
modules/custom/my_views_plugins/src/Plugin/views/access 
cd modules/custom/my_views_plugins/src/Plugin/views/access 
● create a Time.php file here, copy None.php to start
# my_views_plugins/src/Plugin/views/access/Time.php 
namespace Drupalmy_views_pluginsPluginviewsaccess; 
use DrupalCoreSessionAccountInterface; 
use SymfonyComponentRoutingRoute; 
use DrupalviewsPluginviewsaccessAccessPluginBase; 
class Time extends AccessPluginBase { 
public function summaryTitle() {} 
public function access(AccountInterface $account) {} 
public function alterRouteDefinition(Route $route) {} 
}
# my_views_plugins/src/Plugin/views/access/Time.php 
# Implement all the methods of AccessPluginBase 
class Time extends AccessPluginBase { 
public function summaryTitle() { 
return $this­> 
t('Restricted to a time of day.'); 
} 
public function access(AccountInterface $account) { 
return _my_views_plugin_access(); 
} 
public function alterRouteDefinition(Route $route) { 
$route­> 
setRequirement('_custom_access', 
'_my_views_plugin_access'); 
} 
}
# my_views_plugins/my_views_plugins.module 
function _my_views_plugin_access() { 
$date = new DateTime('now'); 
$hour = $date­> 
format('H'); 
if ($hour >= 22) { 
return DrupalCoreAccessAccessResult::allowed(); 
} 
return DrupalCoreAccessAccessResult::forbidden(); 
}
# D8 Demo
Thank you! 
Further learning: 
● Larry Garfield 
DrupalCon Amsterdam 2014: Drupal 8: The Crash Course 
● Joe Shindelar 
DrupalCon Amsterdam 2014: An Overview of the Drupal 8 
Plugin System

Más contenido relacionado

La actualidad más candente

DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoMagento Dev
 
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8Jake Borr
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with ComposerManuele Menozzi
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern ApproachAlessandro Fiore
 
Voiture tech talk
Voiture tech talkVoiture tech talk
Voiture tech talkHoppinger
 
How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.Jay Bharat
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialChristos Zigkolis
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015Fernando Daciuk
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupalsparkfabrik
 
Providing the ultimate publishing experience
Providing the ultimate publishing experienceProviding the ultimate publishing experience
Providing the ultimate publishing experienceShakeeb Ahmed
 
Pde build
Pde buildPde build
Pde buildOwen Ou
 
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJohan Nilsson
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowDerek Willian Stavis
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginMainak Goswami
 
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDFRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDDrupalCamp Kyiv
 
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...Scott DeLoach
 

La actualidad más candente (20)

DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus Magento
 
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with Composer
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
 
An Introduction to Drupal
An Introduction to DrupalAn Introduction to Drupal
An Introduction to Drupal
 
Voiture tech talk
Voiture tech talkVoiture tech talk
Voiture tech talk
 
How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.
 
Unlocked package
Unlocked packageUnlocked package
Unlocked package
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Providing the ultimate publishing experience
Providing the ultimate publishing experienceProviding the ultimate publishing experience
Providing the ultimate publishing experience
 
Pde build
Pde buildPde build
Pde build
 
wp-cli
wp-cliwp-cli
wp-cli
 
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDFRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
 
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
 

Similar a Views plugins-in-d7-and-d8

Building and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with FeaturesNuvole
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupalDay
 
Drupal distributions - how to build them
Drupal distributions - how to build themDrupal distributions - how to build them
Drupal distributions - how to build themDick Olsson
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and moreAcquia
 
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal StackDecoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stacknuppla
 
Using Composer with Drupal and Drush
Using Composer with Drupal and DrushUsing Composer with Drupal and Drush
Using Composer with Drupal and DrushPantheon
 
Automating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondAutomating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondNuvole
 
Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.Samuel Solís Fuentes
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalPantheon
 
Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7 Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7 Dhinakaran Mani
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DrupalDay
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Vishwash Gaur
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
Using Drupal Features in B-Translator
Using Drupal Features in B-TranslatorUsing Drupal Features in B-Translator
Using Drupal Features in B-TranslatorDashamir Hoxha
 
Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012Bastian Grimm
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS DrupalMumbai
 
Towards the perfect Drupal Dev Machine
Towards the perfect Drupal Dev MachineTowards the perfect Drupal Dev Machine
Towards the perfect Drupal Dev MachineKrimson
 

Similar a Views plugins-in-d7-and-d8 (20)

Building and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with Features
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 
Drupal distributions - how to build them
Drupal distributions - how to build themDrupal distributions - how to build them
Drupal distributions - how to build them
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
 
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal StackDecoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
 
Using Composer with Drupal and Drush
Using Composer with Drupal and DrushUsing Composer with Drupal and Drush
Using Composer with Drupal and Drush
 
Automating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondAutomating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyond
 
Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for Drupal
 
Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7 Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8
 
Welcome aboard the team
Welcome aboard the teamWelcome aboard the team
Welcome aboard the team
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Using Drupal Features in B-Translator
Using Drupal Features in B-TranslatorUsing Drupal Features in B-Translator
Using Drupal Features in B-Translator
 
Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
 
Towards the perfect Drupal Dev Machine
Towards the perfect Drupal Dev MachineTowards the perfect Drupal Dev Machine
Towards the perfect Drupal Dev Machine
 

Último

VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...SUHANI PANDEY
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445ruhi
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...SUHANI PANDEY
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...SUHANI PANDEY
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubaikojalkojal131
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftAanSulistiyo
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...nilamkumrai
 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...SUHANI PANDEY
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfJOHNBEBONYAP1
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...SUHANI PANDEY
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...roncy bisnoi
 

Último (20)

VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 

Views plugins-in-d7-and-d8

  • 1. # Views Plugins in Drupal 7 and Drupal 8 ● Michael Lenahan, Developer at erdfisch ● http://drupalcamp.berlin/program/sessions/views­plugins­d7­and­d8
  • 2. # Key Points ● In D7, views is extensible through plugins ● In D8, all of Drupal is extensible through plugins ● In D7, Views is object­oriented ● In D8, All of Drupal is object­oriented
  • 3. # tutorial and documentation # Source: http://www.codem0nk3y.com/2012/04/what­bugs­me­about­modx­and­why/ cms­learning­curve/
  • 4. Drupal 7 ­­­setup # enable views and views_ui drush en ­y views_ui # enable the frontpage view at: # admin/structure/views # set 'Default front page' to 'frontpage' at: # admin/config/system/site­information # add some content
  • 6. # Drupal 7 # Mummy, where do views plugins come from?
  • 7. # Look in s/a/m/contrib/views/includes/plugins.inc # All the 'native' views plugins are declared there. /** * Implements hook_views_plugins(). */ function views_views_plugins() { $plugins = array( // display, style, row, argument default, argument validator and access. ● So we will also need to implement hook_views_plugins().
  • 8. # drupal 7 cd sites/all/modules/contrib/views/plugins && ls
  • 9. class views_plugin_access_none extends views_plugin_access class views_plugin_access_perm extends views_plugin_access class views_plugin_access_role extends views_plugin_access
  • 10. # using sublime text (ctrl p) # alternatively, use grep on the command line: grep ­rin 'extends views_plugin' .
  • 11. # Look in s/a/m/contrib/views/includes/plugins.inc # Views declares its own plugins by implementing hook_views_plugins(). function views_views_plugins() { $plugins = array( // display, style, row, argument default, argument validator and access. 'access' => array( 'none' => array( 'title' => t('None'), 'help' => t('Will be available to all users.'), 'handler' => 'views_plugin_access_none', 'help topic' => 'access­none', ),
  • 12. # Let's create a D7 custom views access plugin
  • 13. # Let's create a D7 custom views access plugin mkdir ­p sites/all/modules/custom/my_views_plugins cd sites/all/modules/custom/my_views_plugins # Create a file named my_views_plugins.info: name = My Views Plugins description = Some views plugins examples. core = 7.x # Create an empty file named my_views_plugins.module.
  • 14. # Enable our empty D7 module by browsing to: admin/modules
  • 15. # In D7, we need to tell Drupal we are using views. # Copy the following text into my_views_plugins.module: <?php /** * Implements hook_views_api(). */ function my_views_plugin_views_api() { return array( 'api' => '3', ); }
  • 16. # In D7, we need to implement hook_views_plugins(). # Create the following file: s/a/m/custom/my_views_plugins/my_views_plugin.views.inc function my_views_plugin_views_plugins() { $plugins = array(); // Tip: copy from: sites/all/modules/contrib/views/includes/plugins.inc $plugins['access'] = array( 'time' => array( 'title' => t('Time'), 'help' => t('Access will be granted according to time of day.'), 'handler' => 'views_plugin_access_time', ), ); return $plugins; }
  • 17. # We still need to tell D7 about the .inc file. # Add the files[] line to my_views_plugin.info: name = My Views Plugins description = Some views plugins examples. core = 7.x files[] = plugins/views_plugin_access_time.inc
  • 18. # Clear the cache (drush cc views or admin/config/development/performance) # Reload: admin/structure/views/view/frontpage/edit
  • 19.
  • 20. # Now write the actual plugin class: # my_views_plugins/plugins/views_plugin_access_time.inc class views_plugin_access_time extends views_plugin_access { // Override the base class methods. function access($account) { return _my_views_plugin_access(); } function get_access_callback() { return array('_my_views_plugin_access'); }
  • 21. # my_views_plugin.module function _my_views_plugin_access() { $date = new DateTime('now'); $hour = $date­> format('H'); if ($hour > 22) { // The children are in bed. return TRUE; } return FALSE; }
  • 22. # This Demo is brought to you by Funny Cat
  • 23. # Views Plugins in Drupal 8 mkdir ­p modules/custom/my_views_plugins cd modules/custom/my_views_plugins # Create a file named my_views_plugins.info.yml name: My Views Plugins type: module description: Some views plugins examples. core: 8.x # Create an empty my_views_plugins.module file <?php
  • 24. # Enable our empty D8 module by browsing to: admin/modules
  • 25. # In Drupal 8, views access plugins are to be found in a predictable location. # This means that they can be easily discovered! core/modules/user/src/Plugin/views/access/Permission.php core/modules/user/src/Plugin/views/access/Role.php core/modules/views/src/Plugin/views/access/None.php ● So, let's create the same directory structure … (cd to your drupal­8 root) mkdir ­p modules/custom/my_views_plugins/src/Plugin/views/access cd modules/custom/my_views_plugins/src/Plugin/views/access ● create a Time.php file here, copy None.php to start
  • 26. # my_views_plugins/src/Plugin/views/access/Time.php namespace Drupalmy_views_pluginsPluginviewsaccess; use DrupalCoreSessionAccountInterface; use SymfonyComponentRoutingRoute; use DrupalviewsPluginviewsaccessAccessPluginBase; class Time extends AccessPluginBase { public function summaryTitle() {} public function access(AccountInterface $account) {} public function alterRouteDefinition(Route $route) {} }
  • 27. # my_views_plugins/src/Plugin/views/access/Time.php # Implement all the methods of AccessPluginBase class Time extends AccessPluginBase { public function summaryTitle() { return $this­> t('Restricted to a time of day.'); } public function access(AccountInterface $account) { return _my_views_plugin_access(); } public function alterRouteDefinition(Route $route) { $route­> setRequirement('_custom_access', '_my_views_plugin_access'); } }
  • 28. # my_views_plugins/my_views_plugins.module function _my_views_plugin_access() { $date = new DateTime('now'); $hour = $date­> format('H'); if ($hour >= 22) { return DrupalCoreAccessAccessResult::allowed(); } return DrupalCoreAccessAccessResult::forbidden(); }
  • 30. Thank you! Further learning: ● Larry Garfield DrupalCon Amsterdam 2014: Drupal 8: The Crash Course ● Joe Shindelar DrupalCon Amsterdam 2014: An Overview of the Drupal 8 Plugin System