SlideShare a Scribd company logo
# 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

More Related Content

What's hot

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 8
Jake Borr
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with Composer
Manuele Menozzi
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
Alessandro Fiore
 
Voiture tech talk
Voiture tech talkVoiture tech talk
Voiture tech talk
Hoppinger
 
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
 
Unlocked package
Unlocked packageUnlocked package
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
Christos 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 2015
Fernando Daciuk
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
sparkfabrik
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
Omnia Helmi
 
Providing the ultimate publishing experience
Providing the ultimate publishing experienceProviding the ultimate publishing experience
Providing the ultimate publishing experience
Shakeeb Ahmed
 
Pde build
Pde buildPde build
Pde build
Owen Ou
 
wp-cli
wp-cliwp-cli
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
Johan 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 now
Derek 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 SKILLD
DrupalCamp 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
 

What's hot (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 to 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 Features
Nuvole
 
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
DrupalDay
 
Drupal distributions - how to build them
Drupal distributions - how to build themDrupal distributions - how to build them
Drupal distributions - how to build them
Dick Olsson
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
Shabir 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 more
Acquia
 
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
nuppla
 
Using Composer with Drupal and Drush
Using Composer with Drupal and DrushUsing Composer with Drupal and Drush
Using Composer with Drupal and Drush
Pantheon
 
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 Drupal
Pantheon
 
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 8
DrupalDay
 
Welcome aboard the team
Welcome aboard the teamWelcome aboard the team
Welcome aboard the team
Roberto Peruzzo
 
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
Vishwash 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-Translator
Dashamir Hoxha
 
Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012
Bastian 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
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
Aggelos Synadakis
 
Towards the perfect Drupal Dev Machine
Towards the perfect Drupal Dev MachineTowards the perfect Drupal Dev Machine
Towards the perfect Drupal Dev Machine
Krimson
 

Similar to 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
 

Recently uploaded

This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
VivekSinghShekhawat2
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 

Recently uploaded (20)

This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 

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