On Github socketwench / portingFlagToDrupal8
(We're hiring!)
I work as a developer with Blink Reaction. We're soon to be the world's largest Drupal Development Consultancy. We're hiring! You can talk to me after the session, tell me about your project, or talk to anyone at the booth outside.
Stored as an Entity since 7.x-2.x
May be attached to one entity type, but...
...multiple bundles of the same type
Created under Admin > Structure > Flags
May be fielded (7.x-3.x)
Which flag was set?
On what entity was the flag set?
When was the flag set?
Who set the flag?
$flag = flag_flag::factory_by_array($bigOlArray); $flag = flag_flag::factory_by_entity_type($entity_type); $flag = flag_flag::factory_by_row($databaseRow);
interface FlagInterface extends ConfigEntityInterface { public function enable(); public function disable(); public function isFlagged(EntityInterface $entity, AccountInterface $account = NULL); public function getPermissions(); public function isGlobal(); public function setGlobal($isGlobal); ...
class Flag extends ConfigEntityBundleBase implements FlagInterface
flag.flag.*: type: config_entity label: 'Flag' mapping: id: type: string label: 'Flag identifier' is_global: type: boolean label: 'Is flag global' flag_short: type: string label: 'Flag Link Text' unflag_short: type: string label: 'Unflag Link Text'
ConfigEntityBase::get($property_name); ConfigEntityBase::set($property_name, $value);
/** @ConfigEntityType( * id = "flag", * label = @Translation("Flag"), * admin_permission = "administer flags", * handlers = { * "list_builder" = "Drupal\flag\Controller\FlagListController", * "form" = { * "add" = "Drupal\flag\Form\FlagAddForm", * "edit" = "Drupal\flag\Form\FlagEditForm", * "delete" = "Drupal\flag\Form\FlagDeleteForm" * } * }, * links = { * "edit-form" = "/admin/structure/flags/manage/{flag}", * "delete-form" = "/admin/structure/flags/manage/{flag}/delete", * } * ) **/
/** * handlers = { * "list_builder" = "Drupal\flag\Controller\FlagListController", * "form" = { * "add" = "Drupal\flag\Form\FlagAddForm", * "edit" = "Drupal\flag\Form\FlagEditForm", * "delete" = "Drupal\flag\Form\FlagDeleteForm" * } * }, */
// Builds the header of the table. FlagListController::buildHeader(); // Populates each row of the table. FlagListController::buildRow($entity);
*.yml files, interfaces, base classes, base forms
Necessary, but tedious to write
Most Drupal 8 modules will contain a lot of scaffolding code. This includes *.yml files, interfaces, base classes, and base forms. It's all necessary (not to mention common for OOP) but tedious to write.drupalconsole.com
https://www.drupal.org/project/console
Drupal Console is open source and you can download it from drupalconsole.com or D.O.final class FlagEvents { const ENTITY_FLAGGED = 'flag.entity_flagged'; const ENTITY_UNFLAGGED = 'flag.entity_unflagged'; const FLAG_DELETED = 'flag.flag_deleted'; const FLAG_RESET = 'flag.flag_reset'; }
public function __construct(ModuleHandlerInterface $module_handler) { $this->moduleHandler = $module_handler; }
Learn and contribute to Drupal Core
Mentors will help you setup and find issues
Friday 9am - 6pm, Room 403AB