SlideShare une entreprise Scribd logo
1  sur  43
Beans, Beans - They’re
Good For Your... Editors
Drupalcamp Chicago 2011
December 10th, 2011
Neil Hastings
BEANS

Neil Hastings
‣ Senior Engineering
‣ Treehouse Agency
‣ @indytechcook




                       Drupal Camp Indy 2011, Neil Hastings
BEANS

What is a BEAN?




            Drupacamp Chicago 2011, Neil Hastings
BEANS

What is a BEAN?
‣ Block Entity




                 Drupacamp Chicago 2011, Neil Hastings
BEANS

What is a BEAN?
‣ Block Entity
‣ BEAN Entities Aren’t Nodes
 ‣ BEAN Entities Aren’t Nodes
   ‣   BEAN Entities Aren’t Nodes
       ‣   BEAN Entities Aren’t Nodes

           ‣   BEAN Entities Aren’t Nodes




                                            Drupacamp Chicago 2011, Neil Hastings
BEANS

What is a BEAN?
‣ Block Entity
‣ BEAN Entities Aren’t Nodes
 ‣ BEAN Entities Aren’t Nodes
   ‣   BEAN Entities Aren’t Nodes
       ‣   BEAN Entities Aren’t Nodes

           ‣   BEAN Entities Aren’t Nodes



‣ A Healthy Way for users to Create
  Blocks
                                            Drupacamp Chicago 2011, Neil Hastings
Blocks on Energy.gov
BEANS




Block Creator
     !=
Administrator


      Drupacamp Chicago 2011, Neil Hastings
BEANS

User generated Blocks
‣ Node-like blocks
 ‣ Fields
 ‣ Templates
‣ Listing blocks
 ‣ User-defined filters
 ‣ Pre-defined styles

                     Drupacamp Chicago 2011, Neil Hastings
screenshot of listing
block example, with
highlights like previous
slide
screenshot of listing
block example, with
highlights like previous
slide
BEANS

Block Entities
‣ Block types
‣ Fieldable
‣ Entity API
‣ Non-admin permissions
‣ Data entry is familiar to users
‣ Build is familiar to Site Builders

                     Drupacamp Chicago 2011, Neil Hastings
BEANS

Coding Concepts




           Drupacamp Chicago 2011, Neil Hastings
BEANS

Coding Concepts
‣ API First




              Drupacamp Chicago 2011, Neil Hastings
BEANS

Coding Concepts
‣ API First
‣ Every Type is a Plugin
 ‣ Even the UI types




                    Drupacamp Chicago 2011, Neil Hastings
BEANS

Coding Concepts
‣ API First
‣ Every Type is a Plugin
 ‣ Even the UI types
‣ Two levels of configuration storage
 ‣ “Config” - BEAN Type/Bundle
 ‣ “Content” - BEAN/Entity
 ‣ Block Placement - BOTH!
                    Drupacamp Chicago 2011, Neil Hastings
BEANS




Drupacamp Chicago 2011, Neil Hastings
BEANS




SHOW ME SOME CODE ALREADY



            Drupacamp Chicago 2011, Neil Hastings
BEANS

Code For All
‣ META




               Drupacamp Chicago 2011, Neil Hastings
BEANS

Show me the Plugin




            Drupacamp Chicago 2011, Neil Hastings
BEANS

We all love Classes
‣ Extend the base class.
  ‣ bean_plugin
  ‣ bean_custom - If bean type will be editable in
    the UI
‣ Implement Methods
  ‣ Values - Define settings to be saved against
    the Bean.
  ‣ Form - Define Form for bean add/edit
  ‣ View - Render the bean.

                           Drupacamp Chicago 2011, Neil Hastings
BEANS

Define Class
class blog_listing_bean extends bean_plugin {
.
.
}




                              Drupacamp Chicago 2011, Neil Hastings
BEANS
Define Values
public function values() {
    return array(
     'filters' => array(
         'term' => FALSE,
         'topic' => FALSE,
         'audience' => FALSE,
     ),
     'items_per_page' => array(
         'large_image' => 0,
         'small_image' => 0,
         'listing' => 0,
     ),
     'more_link' => array(
         'text' => '',
         'path' => '',
     ),
    );
}
                                  Drupacamp Chicago 2011, Neil Hastings
BEANS
Define Values
public function values() {
    return array(
     'filters' => array(
         'term' => FALSE,
         'topic' => FALSE,
         'audience' => FALSE,
     ),
     'items_per_page' => array(
         'large_image' => 0,
         'small_image' => 0,
         'listing' => 0,
     ),
     'more_link' => array(
         'text' => '',
         'path' => '',
     ),
    );
}
                                  Drupacamp Chicago 2011, Neil Hastings
BEANS
Define Values
public function values() {
    return array(
     'filters' => array(
         'term' => FALSE,
         'topic' => FALSE,
         'audience' => FALSE,
     ),
     'items_per_page' => array(
         'large_image' => 0,
         'small_image' => 0,
         'listing' => 0,
     ),
     'more_link' => array(
         'text' => '',
         'path' => '',
     ),
    );
}
                                  Drupacamp Chicago 2011, Neil Hastings
BEANS
Define Values
public function values() {
    return array(
     'filters' => array(
         'term' => FALSE,
         'topic' => FALSE,
         'audience' => FALSE,
     ),
     'items_per_page' => array(
         'large_image' => 0,
         'small_image' => 0,
         'listing' => 0,
     ),
     'more_link' => array(
         'text' => '',
         'path' => '',
     ),
    );
}
                                  Drupacamp Chicago 2011, Neil Hastings
BEANS

Form for All
public function form($bean) {
    $form['more_link']['text'] = array(
     '#type' => 'textfield',
     '#title' => t('Link text'),
     '#default_value' => $bean->more_link['text'],
    );


    $form['more_link']['path'] = array(
     '#type' => 'textfield',
     '#title' => t('Link path'),
     '#default_value' => $bean->more_link['path'],
    );
}

                                      Drupacamp Chicago 2011, Neil Hastings
BEANS

Form for All
public function form($bean) {
    $form['more_link']['text'] = array(
     '#type' => 'textfield',
     '#title' => t('Link text'),
     '#default_value' => $bean->more_link['text'],
    );


    $form['more_link']['path'] = array(
     '#type' => 'textfield',
     '#title' => t('Link path'),
     '#default_value' => $bean->more_link['path'],
    );
}

                                      Drupacamp Chicago 2011, Neil Hastings
BEANS

A Bean with a View
public function view($bean, $content, $view_mode =
'full', $langcode = NULL) {
}



    ‣ Return a Render Array




                            Drupacamp Chicago 2011, Neil Hastings
BEANS
  $count = $bean->items_per_page['large_image'] + $bean->items_per_page['small_image'] + $bean-
>items_per_page['listing'];


  $query = new EnergyEntityFieldQuery();
  $query
      ->entityCondition('bundle', 'article')
      ->clearAudienceConditions()
      ->setOtherAudienceCondition()
      ->range(0, $count);


  if (!empty($bean->filters['term'])) {
      $query->setTermCondition('field_article_type', $bean->filters['term']);
  }


  if (!empty($bean->filters['topic'])) {
      $query->setTopicCondition($bean->filters['topic']);
  }


  if (!empty($bean->filters['audience'])) {
      $query->setTermCondition('field_audience_term', $bean->filters['audience']);
  }


  $result = $query->execute();

                                                       Drupacamp Chicago 2011, Neil Hastings
BEANS
if (empty($result)) {
    $content['nodes'] = array();
}
else {
    $content['nodes'] = node_load_multiple(array_keys($result['node']));
}


$content['#theme'] = 'energy_blog_list';
$content['more_link'] = array(
    'text' => $bean->more_link['text'],
    'path' => $bean->more_link['path'],
);
$content['items_per_page'] = array(
    'large_image' => $bean->items_per_page['large_image'],
    'small_image' => $bean->items_per_page['small_image'],
    'listing' => $bean->items_per_page['listing'],
);
                                      Drupacamp Chicago 2011, Neil Hastings
BEANS
if (empty($result)) {
    $content['nodes'] = array();
}
else {
    $content['nodes'] = node_load_multiple(array_keys($result['node']));
}


$content['#theme'] = 'energy_blog_list';
$content['more_link'] = array(
    'text' => $bean->more_link['text'],
    'path' => $bean->more_link['path'],
);
$content['items_per_page'] = array(
    'large_image' => $bean->items_per_page['large_image'],
    'small_image' => $bean->items_per_page['small_image'],
    'listing' => $bean->items_per_page['listing'],
);
                                      Drupacamp Chicago 2011, Neil Hastings
BEANS
if (empty($result)) {
    $content['nodes'] = array();
}
else {
    $content['nodes'] = node_load_multiple(array_keys($result['node']));
}


$content['#theme'] = 'energy_blog_list';
$content['more_link'] = array(
    'text' => $bean->more_link['text'],
    'path' => $bean->more_link['path'],
);
$content['items_per_page'] = array(
    'large_image' => $bean->items_per_page['large_image'],
    'small_image' => $bean->items_per_page['small_image'],
    'listing' => $bean->items_per_page['listing'],
);
                                      Drupacamp Chicago 2011, Neil Hastings
BEANS
if (empty($result)) {
    $content['nodes'] = array();
}
else {
    $content['nodes'] = node_load_multiple(array_keys($result['node']));
}


$content['#theme'] = 'energy_blog_list';
$content['more_link'] = array(
    'text' => $bean->more_link['text'],
    'path' => $bean->more_link['path'],
);
$content['items_per_page'] = array(
    'large_image' => $bean->items_per_page['large_image'],
    'small_image' => $bean->items_per_page['small_image'],
    'listing' => $bean->items_per_page['listing'],
);
                                      Drupacamp Chicago 2011, Neil Hastings
screenshot of listing
block example, with
highlights like previous
slide
screenshot of listing
block example, with
highlights like previous
slide
BEANS

Editorial listings
‣ Hand-selected listings of nodes
‣ Multiple Node Reference field
‣ View mode set in the Node
  Reference field settings
‣ Additional fields
  ‣ More link, Header text, etc.


                     Drupacamp Chicago 2011, Neil Hastings
BEANS

More Fun!
‣ http://treehouseagency.com/blog/
  neil-hastings/2011/09/21/
  building-custom-block-entities-
  beans
‣ http://treehouseagency.com/blog/
  neil-hastings/2011/09/06/
  building-energygov-without-views
‣ http://drupal.org/project/bean

                   Drupacamp Chicago 2011, Neil Hastings

Contenu connexe

Tendances (6)

Functionality Focused Code Organization
Functionality Focused Code OrganizationFunctionality Focused Code Organization
Functionality Focused Code Organization
 
究極のコントローラを目指す
究極のコントローラを目指す究極のコントローラを目指す
究極のコントローラを目指す
 
Zf Zend Db by aida
Zf Zend Db by aidaZf Zend Db by aida
Zf Zend Db by aida
 
Customizing the list control - Sencha Touch mobile web application
Customizing the list control - Sencha Touch mobile web applicationCustomizing the list control - Sencha Touch mobile web application
Customizing the list control - Sencha Touch mobile web application
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentation
 
When Relational Isn't Enough: Neo4j at Squidoo
When Relational Isn't Enough: Neo4j at SquidooWhen Relational Isn't Enough: Neo4j at Squidoo
When Relational Isn't Enough: Neo4j at Squidoo
 

En vedette

Modern Theming: Beyond Proprocessing and .tpls
Modern Theming: Beyond Proprocessing and .tplsModern Theming: Beyond Proprocessing and .tpls
Modern Theming: Beyond Proprocessing and .tpls
Treehouse Agency
 

En vedette (6)

Energy.gov Case Study - BADcamp 2011
Energy.gov Case Study - BADcamp 2011Energy.gov Case Study - BADcamp 2011
Energy.gov Case Study - BADcamp 2011
 
DruplCampNYC 10 - Energy.gov Case Study
DruplCampNYC 10 - Energy.gov Case StudyDruplCampNYC 10 - Energy.gov Case Study
DruplCampNYC 10 - Energy.gov Case Study
 
Cammie Croft's Lightning Talk Presentation
Cammie Croft's Lightning Talk PresentationCammie Croft's Lightning Talk Presentation
Cammie Croft's Lightning Talk Presentation
 
Modern Theming: Beyond Proprocessing and .tpls
Modern Theming: Beyond Proprocessing and .tplsModern Theming: Beyond Proprocessing and .tpls
Modern Theming: Beyond Proprocessing and .tpls
 
Secretary Moniz's FY 2016 Budget Presentation
Secretary Moniz's FY 2016 Budget PresentationSecretary Moniz's FY 2016 Budget Presentation
Secretary Moniz's FY 2016 Budget Presentation
 
Fy 2015 budget rollout secretary moniz presentation to press and stakeholders
Fy 2015 budget rollout   secretary moniz presentation to press and stakeholdersFy 2015 budget rollout   secretary moniz presentation to press and stakeholders
Fy 2015 budget rollout secretary moniz presentation to press and stakeholders
 

Similaire à Drupal Block Entities - Drupalcamp Chicago 2011

Information Science Blog Aggregation
Information Science Blog AggregationInformation Science Blog Aggregation
Information Science Blog Aggregation
Franny Gaede
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
unodelostrece
 
The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J Query
QConLondon2008
 
WPSessions - Thinking Outside The Box With BuddyPress
WPSessions - Thinking Outside The Box With BuddyPressWPSessions - Thinking Outside The Box With BuddyPress
WPSessions - Thinking Outside The Box With BuddyPress
David Bisset
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
Tyler Brock
 

Similaire à Drupal Block Entities - Drupalcamp Chicago 2011 (20)

BAD Beans
BAD BeansBAD Beans
BAD Beans
 
Information Science Blog Aggregation
Information Science Blog AggregationInformation Science Blog Aggregation
Information Science Blog Aggregation
 
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa HallPitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
 
Creating Operational Redundancy for Effective Web Data Mining
Creating Operational Redundancy for Effective Web Data MiningCreating Operational Redundancy for Effective Web Data Mining
Creating Operational Redundancy for Effective Web Data Mining
 
Riak with node.js
Riak with node.jsRiak with node.js
Riak with node.js
 
It's 2017, and I still want to sell you a graph database
It's 2017, and I still want to sell you a graph databaseIt's 2017, and I still want to sell you a graph database
It's 2017, and I still want to sell you a graph database
 
Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Your code sucks, let's fix it - PHP Master Series 2012
Your code sucks, let's fix it - PHP Master Series 2012Your code sucks, let's fix it - PHP Master Series 2012
Your code sucks, let's fix it - PHP Master Series 2012
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
 
The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J Query
 
WPSessions - Thinking Outside The Box With BuddyPress
WPSessions - Thinking Outside The Box With BuddyPressWPSessions - Thinking Outside The Box With BuddyPress
WPSessions - Thinking Outside The Box With BuddyPress
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Let's write secure Drupal code! Drupal MountainCamp 2019
Let's write secure Drupal code! Drupal MountainCamp 2019Let's write secure Drupal code! Drupal MountainCamp 2019
Let's write secure Drupal code! Drupal MountainCamp 2019
 
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan ShroyerJoomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Drupal Block Entities - Drupalcamp Chicago 2011

  • 1. Beans, Beans - They’re Good For Your... Editors Drupalcamp Chicago 2011 December 10th, 2011 Neil Hastings
  • 2. BEANS Neil Hastings ‣ Senior Engineering ‣ Treehouse Agency ‣ @indytechcook Drupal Camp Indy 2011, Neil Hastings
  • 3. BEANS What is a BEAN? Drupacamp Chicago 2011, Neil Hastings
  • 4. BEANS What is a BEAN? ‣ Block Entity Drupacamp Chicago 2011, Neil Hastings
  • 5. BEANS What is a BEAN? ‣ Block Entity ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes Drupacamp Chicago 2011, Neil Hastings
  • 6. BEANS What is a BEAN? ‣ Block Entity ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes ‣ BEAN Entities Aren’t Nodes ‣ A Healthy Way for users to Create Blocks Drupacamp Chicago 2011, Neil Hastings
  • 8. BEANS Block Creator != Administrator Drupacamp Chicago 2011, Neil Hastings
  • 9. BEANS User generated Blocks ‣ Node-like blocks ‣ Fields ‣ Templates ‣ Listing blocks ‣ User-defined filters ‣ Pre-defined styles Drupacamp Chicago 2011, Neil Hastings
  • 10.
  • 11.
  • 12. screenshot of listing block example, with highlights like previous slide
  • 13. screenshot of listing block example, with highlights like previous slide
  • 14.
  • 15. BEANS Block Entities ‣ Block types ‣ Fieldable ‣ Entity API ‣ Non-admin permissions ‣ Data entry is familiar to users ‣ Build is familiar to Site Builders Drupacamp Chicago 2011, Neil Hastings
  • 16.
  • 17.
  • 18. BEANS Coding Concepts Drupacamp Chicago 2011, Neil Hastings
  • 19. BEANS Coding Concepts ‣ API First Drupacamp Chicago 2011, Neil Hastings
  • 20. BEANS Coding Concepts ‣ API First ‣ Every Type is a Plugin ‣ Even the UI types Drupacamp Chicago 2011, Neil Hastings
  • 21. BEANS Coding Concepts ‣ API First ‣ Every Type is a Plugin ‣ Even the UI types ‣ Two levels of configuration storage ‣ “Config” - BEAN Type/Bundle ‣ “Content” - BEAN/Entity ‣ Block Placement - BOTH! Drupacamp Chicago 2011, Neil Hastings
  • 23. BEANS SHOW ME SOME CODE ALREADY Drupacamp Chicago 2011, Neil Hastings
  • 24. BEANS Code For All ‣ META Drupacamp Chicago 2011, Neil Hastings
  • 25. BEANS Show me the Plugin Drupacamp Chicago 2011, Neil Hastings
  • 26. BEANS We all love Classes ‣ Extend the base class. ‣ bean_plugin ‣ bean_custom - If bean type will be editable in the UI ‣ Implement Methods ‣ Values - Define settings to be saved against the Bean. ‣ Form - Define Form for bean add/edit ‣ View - Render the bean. Drupacamp Chicago 2011, Neil Hastings
  • 27. BEANS Define Class class blog_listing_bean extends bean_plugin { . . } Drupacamp Chicago 2011, Neil Hastings
  • 28. BEANS Define Values public function values() { return array( 'filters' => array( 'term' => FALSE, 'topic' => FALSE, 'audience' => FALSE, ), 'items_per_page' => array( 'large_image' => 0, 'small_image' => 0, 'listing' => 0, ), 'more_link' => array( 'text' => '', 'path' => '', ), ); } Drupacamp Chicago 2011, Neil Hastings
  • 29. BEANS Define Values public function values() { return array( 'filters' => array( 'term' => FALSE, 'topic' => FALSE, 'audience' => FALSE, ), 'items_per_page' => array( 'large_image' => 0, 'small_image' => 0, 'listing' => 0, ), 'more_link' => array( 'text' => '', 'path' => '', ), ); } Drupacamp Chicago 2011, Neil Hastings
  • 30. BEANS Define Values public function values() { return array( 'filters' => array( 'term' => FALSE, 'topic' => FALSE, 'audience' => FALSE, ), 'items_per_page' => array( 'large_image' => 0, 'small_image' => 0, 'listing' => 0, ), 'more_link' => array( 'text' => '', 'path' => '', ), ); } Drupacamp Chicago 2011, Neil Hastings
  • 31. BEANS Define Values public function values() { return array( 'filters' => array( 'term' => FALSE, 'topic' => FALSE, 'audience' => FALSE, ), 'items_per_page' => array( 'large_image' => 0, 'small_image' => 0, 'listing' => 0, ), 'more_link' => array( 'text' => '', 'path' => '', ), ); } Drupacamp Chicago 2011, Neil Hastings
  • 32. BEANS Form for All public function form($bean) { $form['more_link']['text'] = array( '#type' => 'textfield', '#title' => t('Link text'), '#default_value' => $bean->more_link['text'], ); $form['more_link']['path'] = array( '#type' => 'textfield', '#title' => t('Link path'), '#default_value' => $bean->more_link['path'], ); } Drupacamp Chicago 2011, Neil Hastings
  • 33. BEANS Form for All public function form($bean) { $form['more_link']['text'] = array( '#type' => 'textfield', '#title' => t('Link text'), '#default_value' => $bean->more_link['text'], ); $form['more_link']['path'] = array( '#type' => 'textfield', '#title' => t('Link path'), '#default_value' => $bean->more_link['path'], ); } Drupacamp Chicago 2011, Neil Hastings
  • 34. BEANS A Bean with a View public function view($bean, $content, $view_mode = 'full', $langcode = NULL) { } ‣ Return a Render Array Drupacamp Chicago 2011, Neil Hastings
  • 35. BEANS $count = $bean->items_per_page['large_image'] + $bean->items_per_page['small_image'] + $bean- >items_per_page['listing']; $query = new EnergyEntityFieldQuery(); $query ->entityCondition('bundle', 'article') ->clearAudienceConditions() ->setOtherAudienceCondition() ->range(0, $count); if (!empty($bean->filters['term'])) { $query->setTermCondition('field_article_type', $bean->filters['term']); } if (!empty($bean->filters['topic'])) { $query->setTopicCondition($bean->filters['topic']); } if (!empty($bean->filters['audience'])) { $query->setTermCondition('field_audience_term', $bean->filters['audience']); } $result = $query->execute(); Drupacamp Chicago 2011, Neil Hastings
  • 36. BEANS if (empty($result)) { $content['nodes'] = array(); } else { $content['nodes'] = node_load_multiple(array_keys($result['node'])); } $content['#theme'] = 'energy_blog_list'; $content['more_link'] = array( 'text' => $bean->more_link['text'], 'path' => $bean->more_link['path'], ); $content['items_per_page'] = array( 'large_image' => $bean->items_per_page['large_image'], 'small_image' => $bean->items_per_page['small_image'], 'listing' => $bean->items_per_page['listing'], ); Drupacamp Chicago 2011, Neil Hastings
  • 37. BEANS if (empty($result)) { $content['nodes'] = array(); } else { $content['nodes'] = node_load_multiple(array_keys($result['node'])); } $content['#theme'] = 'energy_blog_list'; $content['more_link'] = array( 'text' => $bean->more_link['text'], 'path' => $bean->more_link['path'], ); $content['items_per_page'] = array( 'large_image' => $bean->items_per_page['large_image'], 'small_image' => $bean->items_per_page['small_image'], 'listing' => $bean->items_per_page['listing'], ); Drupacamp Chicago 2011, Neil Hastings
  • 38. BEANS if (empty($result)) { $content['nodes'] = array(); } else { $content['nodes'] = node_load_multiple(array_keys($result['node'])); } $content['#theme'] = 'energy_blog_list'; $content['more_link'] = array( 'text' => $bean->more_link['text'], 'path' => $bean->more_link['path'], ); $content['items_per_page'] = array( 'large_image' => $bean->items_per_page['large_image'], 'small_image' => $bean->items_per_page['small_image'], 'listing' => $bean->items_per_page['listing'], ); Drupacamp Chicago 2011, Neil Hastings
  • 39. BEANS if (empty($result)) { $content['nodes'] = array(); } else { $content['nodes'] = node_load_multiple(array_keys($result['node'])); } $content['#theme'] = 'energy_blog_list'; $content['more_link'] = array( 'text' => $bean->more_link['text'], 'path' => $bean->more_link['path'], ); $content['items_per_page'] = array( 'large_image' => $bean->items_per_page['large_image'], 'small_image' => $bean->items_per_page['small_image'], 'listing' => $bean->items_per_page['listing'], ); Drupacamp Chicago 2011, Neil Hastings
  • 40. screenshot of listing block example, with highlights like previous slide
  • 41. screenshot of listing block example, with highlights like previous slide
  • 42. BEANS Editorial listings ‣ Hand-selected listings of nodes ‣ Multiple Node Reference field ‣ View mode set in the Node Reference field settings ‣ Additional fields ‣ More link, Header text, etc. Drupacamp Chicago 2011, Neil Hastings
  • 43. BEANS More Fun! ‣ http://treehouseagency.com/blog/ neil-hastings/2011/09/21/ building-custom-block-entities- beans ‣ http://treehouseagency.com/blog/ neil-hastings/2011/09/06/ building-energygov-without-views ‣ http://drupal.org/project/bean Drupacamp Chicago 2011, Neil Hastings

Notes de l'éditeur

  1. \n
  2. \n
  3. Beans are Block Entities.\nWhat does BEAN stand for.\n
  4. Beans are Block Entities.\nWhat does BEAN stand for.\n
  5. Beans are Block Entities.\nWhat does BEAN stand for.\n
  6. Before we talk about what beans really are, let’s talk about why we created beans.\n
  7. This site was going to have hundreds of blocks, which needed to be created by normal CMS users. How do we allow users to create blocks without granting them administrative access?\n
  8. After evaluating the designs, we came up with 2 main types of user generated blocks.\n
  9. Here we see 2 “Graphic” blocks. If these were nodes, we would immediately know how to build these. A title, an image field with a link, some body text. Then we style the template, or perhaps if the template isn’t too complicated, we just select the appropriate field formatters for this view mode. But these aren’t nodes, they’re blocks.\n
  10. Here is are the listing blocks.\nThat’s what let us to create Beans\nThe “BLOG” bean we will be creating later\n
  11. That’s what led us to create Beans\n
  12. Ctypes but with Blocks\nBlock types are ctools based plugins\nBlock types are entity bundles\nEntity API module adds views, actions and rules integration\n\n
  13. Bean exposes blocks as a new type of fieldable entity.  Creating new block types and adding fields is as easy as creating new node types (screenshot of block type admin).  Use the display settings for the blocks to control the display output, just like with other fieldable entities (screenshot of “display fields” tab).\n\n
  14. \n
  15. API First\n- Early versions of BEAN had no way of creating block types in the UI\nEvery plugin is a type\nBlock Placement\n- Config if context/block admin\n- Content if block reference/panels\n
  16. API First\n- Early versions of BEAN had no way of creating block types in the UI\nEvery plugin is a type\nBlock Placement\n- Config if context/block admin\n- Content if block reference/panels\n
  17. API First\n- Early versions of BEAN had no way of creating block types in the UI\nEvery plugin is a type\nBlock Placement\n- Config if context/block admin\n- Content if block reference/panels\n
  18. Let’s make a view Block for a listing of blog post. There are 3 different view modes for each node listing. The user needs to be able to select how many of each type of view mode will be used. The user will also select content filter settings.\n
  19. All modules just implement hook_bean_types_api_info\nhook_ctools_plugin_direcory is optional but recommended.\n
  20. Define a Ctools plugin\nIf you are doing a bean with only fields, you can use bean_default as the “class” with no need for “file” or “path”\n
  21. \n
  22. \n
  23. Notice the groups of settings. These help make logical breaks.\nFilters for Content\nView settings per view mode\nMore link for entire block\n
  24. Notice the groups of settings. These help make logical breaks.\nFilters for Content\nView settings per view mode\nMore link for entire block\n
  25. Notice the groups of settings. These help make logical breaks.\nFilters for Content\nView settings per view mode\nMore link for entire block\n
  26. This is just a sample. Just uses standard Form API\n$bean is fully loaded with defaults so no need to check for existence\nTalk about the $bean->more_link[‘text’].\n
  27. Common to use Entity Field Query to create dataset.\n$bean is fully loaded\n$content is the rendered content array up to now. Includes fields\nView mode is not used yet - Oh wait, as of yesterday they are!!\n\n
  28. EntityFieldQuery is awesome\nEnergyEntityFieldQuery\n- Defaults Group\n- Published\n- Easily handle topic vocab\n
  29. Using the theme function “energy_blog_list”\nnodes\nmore_link\nitems_per_page passed\n
  30. Using the theme function “energy_blog_list”\nnodes\nmore_link\nitems_per_page passed\n
  31. Using the theme function “energy_blog_list”\nnodes\nmore_link\nitems_per_page passed\n
  32. Uses view modes to render the article nodes per the 3 different settings groups\nTalk block placement\n\n
  33. Here’s a quick recipe that we used a lot on the site. It is very easy to implement and your users will love it.\n
  34. \n