(We're hiring!)
We need modules ported to Drupal 8 now.-- Angie "webchick" Byron
Enables administrators to define boolean fields that can be attached to site content which each user may set or unset.
Administrator-defined boolean field
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)
Entity created to store when a user sets a Flag.
Which flag was set?
On what entity was the flag set?
When was the flag set?
Who set the flag?
Any entity that has a flag defined and for which flaggings may be created
$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);
EntityConfirmFormBase
directly*.yml files, interfaces, base classes, base forms
Necessary, but tedious to write
drupalconsole.com
https://www.drupal.org/project/console
baseFieldDefinitions()
hook_schema()
$drupal generate:service
\Drupal::service('flag')->flag();
\Drupal::service('flag')->unflag();
@FlagType
annotationfinal 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';
}
ModuleHandlerInterface::invokeAll()
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