SlideShare a Scribd company logo
Beans, Beans - They’re
Good For Your... Editors
BADcamp 2011
October 22nd, 2011
Neil Hastings
BEANS

Neil Hastings
‣ Senior Engineering
‣ Treehouse Agency
‣ Drupal.org member for 3 years and
  34 weeks
‣ @indytechcook



                        BADcamp 2011, Neil Hastings
BEANS

What is a BEAN?




                  BADcamp 2011, Neil Hastings
BEANS

What is a BEAN?
‣ Block Entity




                  BADcamp 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




                                            BADcamp 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
                                            BADcamp 2011, Neil Hastings
Blocks on Energy.gov
BEANS




Block Creator
     !=
Administrator


          BADcamp 2011, Neil Hastings
BEANS

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

                        BADcamp 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

                            BADcamp 2011, Neil Hastings
BEANS

Coding Concepts




                  BADcamp 2011, Neil Hastings
BEANS

Coding Concepts
‣ API First




                  BADcamp 2011, Neil Hastings
BEANS

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




                           BADcamp 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!
                           BADcamp 2011, Neil Hastings
BEANS




BADcamp 2011, Neil Hastings
BEANS




SHOW ME SOME CODE ALREADY



               BADcamp 2011, Neil Hastings
BEANS

Code For All
‣ META




               BADcamp 2011, Neil Hastings
BEANS

Show me the Plugin




                BADcamp 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.

                                 BADcamp 2011, Neil Hastings
BEANS

Define Class
class blog_listing_bean extends bean_plugin {
.
.
}




                                       BADcamp 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' => '',
     ),
    );
}
                                  BADcamp 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' => '',
     ),
    );
}
                                  BADcamp 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' => '',
     ),
    );
}
                                  BADcamp 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' => '',
     ),
    );
}
                                  BADcamp 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'],
    );
}

                                              BADcamp 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'],
    );
}

                                              BADcamp 2011, Neil Hastings
BEANS

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



    ‣ Return a Render Array
    ‣ Currently $view_mode is ignored in
      the block rendering



                                     BADcamp 2011, Neil Hastings
BEANS

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



    ‣ Return a Render Array




                                     BADcamp 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();

                                                                      BADcamp 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'],
);
                                                 BADcamp 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'],
);
                                                 BADcamp 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'],
);
                                                 BADcamp 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'],
);
                                                 BADcamp 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.


                          BADcamp 2011, Neil Hastings
BEANS

More Fun!
‣ BOF in Dwinelle 183 - now
‣ 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

                          BADcamp 2011, Neil Hastings

More Related Content

Similar to BAD Beans

Riak with node.js
Riak with node.jsRiak with node.js
Riak with node.js
Sean Cribbs
 
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
hannonhill
 
Information Science Blog Aggregation
Information Science Blog AggregationInformation Science Blog Aggregation
Information Science Blog AggregationFranny Gaede
 
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
Jonathan LeBlanc
 
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
Rafael Dohms
 
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)
Rafael Dohms
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkTyler Brock
 
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
Rafael Dohms
 
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
Rafael Dohms
 

Similar to BAD Beans (9)

Riak with node.js
Riak with node.jsRiak with node.js
Riak with node.js
 
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
 
Information Science Blog Aggregation
Information Science Blog AggregationInformation Science Blog Aggregation
Information Science Blog Aggregation
 
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
 
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
 
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)
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
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
 

More from Phase2

Phase2 Health and Wellness Brochure
Phase2 Health and Wellness BrochurePhase2 Health and Wellness Brochure
Phase2 Health and Wellness Brochure
Phase2
 
A Modern Digital Experience Platform
A Modern Digital Experience PlatformA Modern Digital Experience Platform
A Modern Digital Experience Platform
Phase2
 
Beyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience PlatformBeyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience Platform
Phase2
 
The Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 TalkThe Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 Talk
Phase2
 
Site building with end user in mind
Site building with end user in mindSite building with end user in mind
Site building with end user in mind
Phase2
 
Fields, entities, lists, oh my!
Fields, entities, lists, oh my!Fields, entities, lists, oh my!
Fields, entities, lists, oh my!
Phase2
 
Performance Profiling Tools and Tricks
Performance Profiling Tools and TricksPerformance Profiling Tools and Tricks
Performance Profiling Tools and Tricks
Phase2
 
NORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShiftNORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShift
Phase2
 
Drupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital LandscapeDrupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital Landscape
Phase2
 
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...
Phase2
 
Site Building with the End User in Mind
Site Building with the End User in MindSite Building with the End User in Mind
Site Building with the End User in Mind
Phase2
 
The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"
Phase2
 
User Testing For Humanitarian ID App
User Testing For Humanitarian ID AppUser Testing For Humanitarian ID App
User Testing For Humanitarian ID App
Phase2
 
Redhat.com: An Architectural Case Study
Redhat.com: An Architectural Case StudyRedhat.com: An Architectural Case Study
Redhat.com: An Architectural Case Study
Phase2
 
The New Design Workflow
The New Design WorkflowThe New Design Workflow
The New Design Workflow
Phase2
 
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Phase2
 
Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8
Phase2
 
How, When, and Why to Patch a Module
How, When, and Why to Patch a Module How, When, and Why to Patch a Module
How, When, and Why to Patch a Module
Phase2
 
Drupal Is Not Your Web Site
Drupal Is Not Your Web SiteDrupal Is Not Your Web Site
Drupal Is Not Your Web Site
Phase2
 
Empathy For Idiots
Empathy For Idiots Empathy For Idiots
Empathy For Idiots
Phase2
 

More from Phase2 (20)

Phase2 Health and Wellness Brochure
Phase2 Health and Wellness BrochurePhase2 Health and Wellness Brochure
Phase2 Health and Wellness Brochure
 
A Modern Digital Experience Platform
A Modern Digital Experience PlatformA Modern Digital Experience Platform
A Modern Digital Experience Platform
 
Beyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience PlatformBeyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience Platform
 
The Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 TalkThe Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 Talk
 
Site building with end user in mind
Site building with end user in mindSite building with end user in mind
Site building with end user in mind
 
Fields, entities, lists, oh my!
Fields, entities, lists, oh my!Fields, entities, lists, oh my!
Fields, entities, lists, oh my!
 
Performance Profiling Tools and Tricks
Performance Profiling Tools and TricksPerformance Profiling Tools and Tricks
Performance Profiling Tools and Tricks
 
NORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShiftNORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShift
 
Drupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital LandscapeDrupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital Landscape
 
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...
 
Site Building with the End User in Mind
Site Building with the End User in MindSite Building with the End User in Mind
Site Building with the End User in Mind
 
The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"
 
User Testing For Humanitarian ID App
User Testing For Humanitarian ID AppUser Testing For Humanitarian ID App
User Testing For Humanitarian ID App
 
Redhat.com: An Architectural Case Study
Redhat.com: An Architectural Case StudyRedhat.com: An Architectural Case Study
Redhat.com: An Architectural Case Study
 
The New Design Workflow
The New Design WorkflowThe New Design Workflow
The New Design Workflow
 
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
 
Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8
 
How, When, and Why to Patch a Module
How, When, and Why to Patch a Module How, When, and Why to Patch a Module
How, When, and Why to Patch a Module
 
Drupal Is Not Your Web Site
Drupal Is Not Your Web SiteDrupal Is Not Your Web Site
Drupal Is Not Your Web Site
 
Empathy For Idiots
Empathy For Idiots Empathy For Idiots
Empathy For Idiots
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

BAD Beans

  • 1. Beans, Beans - They’re Good For Your... Editors BADcamp 2011 October 22nd, 2011 Neil Hastings
  • 2. BEANS Neil Hastings ‣ Senior Engineering ‣ Treehouse Agency ‣ Drupal.org member for 3 years and 34 weeks ‣ @indytechcook BADcamp 2011, Neil Hastings
  • 3. BEANS What is a BEAN? BADcamp 2011, Neil Hastings
  • 4. BEANS What is a BEAN? ‣ Block Entity BADcamp 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 BADcamp 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 BADcamp 2011, Neil Hastings
  • 8. BEANS Block Creator != Administrator BADcamp 2011, Neil Hastings
  • 9. BEANS User generated Blocks ‣ Node-like blocks ‣ Fields ‣ Templates ‣ Listing blocks ‣ User-defined filters ‣ Pre-defined styles BADcamp 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 BADcamp 2011, Neil Hastings
  • 16.
  • 17.
  • 18. BEANS Coding Concepts BADcamp 2011, Neil Hastings
  • 19. BEANS Coding Concepts ‣ API First BADcamp 2011, Neil Hastings
  • 20. BEANS Coding Concepts ‣ API First ‣ Every Type is a Plugin ‣ Even the UI types BADcamp 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! BADcamp 2011, Neil Hastings
  • 23. BEANS SHOW ME SOME CODE ALREADY BADcamp 2011, Neil Hastings
  • 24. BEANS Code For All ‣ META BADcamp 2011, Neil Hastings
  • 25. BEANS Show me the Plugin BADcamp 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. BADcamp 2011, Neil Hastings
  • 27. BEANS Define Class class blog_listing_bean extends bean_plugin { . . } BADcamp 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' => '', ), ); } BADcamp 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' => '', ), ); } BADcamp 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' => '', ), ); } BADcamp 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' => '', ), ); } BADcamp 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'], ); } BADcamp 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'], ); } BADcamp 2011, Neil Hastings
  • 34. BEANS A Bean with a View public function view($bean, $content, $view_mode = 'full', $langcode = NULL) { } ‣ Return a Render Array ‣ Currently $view_mode is ignored in the block rendering BADcamp 2011, Neil Hastings
  • 35. BEANS A Bean with a View public function view($bean, $content, $view_mode = 'full', $langcode = NULL) { } ‣ Return a Render Array BADcamp 2011, Neil Hastings
  • 36. 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(); BADcamp 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'], ); BADcamp 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'], ); BADcamp 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'], ); BADcamp 2011, Neil Hastings
  • 40. 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'], ); BADcamp 2011, Neil Hastings
  • 41. screenshot of listing block example, with highlights like previous slide
  • 42. screenshot of listing block example, with highlights like previous slide
  • 43. 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. BADcamp 2011, Neil Hastings
  • 44. BEANS More Fun! ‣ BOF in Dwinelle 183 - now ‣ 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 BADcamp 2011, Neil Hastings

Editor's Notes

  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