Tim Millwood: Drupal Service ID Collectors

Planet Drupal - 14. Dezember 2017 - 11:29
Drupal Service ID Collectors

Since Drupal 8 we've had services. This also brought the concept of a service collector or tagged services. This allows services to be tagged with a specific tag, then a service collector can collect all services with the a given tag and use whichever service "applies".

As you could imagine loaded all of these tagged services when loading the service collector service can be a performance nightmare, which is why Drupal 8.4.0 brought us service ID collector functionality.

Tagging a service with the service_id_collector tag will pass all services with a given tag as the last parameter in the constructor. This will be an array of service IDs ordered by the priority. You will then need to use the ClassResolver service to lazily instantiate the collected service IDs.

my_module.services.yml
my_module.negotiator:
  class: \Drupal\my_module\MyModuleNegotiator
  arguments: {'@class.resolver'}
  tags:
    - { name: service_id_collector, tag: my_module_negotiator }
my_module.negotiator.foo:
  class:\Drupal\my_module\FooNegotiator
  arguments: {'@entity_type.manager'}
  tags:
    - { name: my_module_negotiator, priority: 100 }
my_module.negotiator.bar:
  class:\Drupal\my_module\BarNegotiator
  arguments: {'@entity_type.manager'}
  tags:
    - { name: my_module_negotiator, priority: -100 }
my_module.negotiator.baz:
  class:\Drupal\my_module\BazNegotiator
  arguments: {'@entity_type.manager'}
  tags:
    - { name: my_module_negotiator, priority: 0 }

MyModuleNegotiator.php
/**
 * The negotiator for my module.
 */
class MyModuleNegotiator {

  /**
   * The class resolver service.
   *
   * @var \Drupal\Core\DependencyInjection\ClassResolver
   */
  protected $classResolver;

  /**
   * The negotiator service IDs.
   *
   * @var array
   */
  protected $negotiatorServiceIds;
 

  /**
   * Constructs the negotiator.
   *
   * @param \Drupal\Core\DependencyInjection\ClassResolver $class_resolver
   *   The class resolver service.
   * @param array $negotiator_service_ids
   *   The negotiator service IDs.
   */
  public function __construct(ClassResolverInterface $class_resolver, array $negotiator_service_ids) {
    $this->classResolver = $class_resolver;
    $this->negotiatorServiceIds = $negotiator_service_ids;
  }
 

  /**
   * Run the negotiators.
   */
  public function runNegotiators() {
    foreach ($this->negotiatorServiceIds as $negotiator_service_id) {
      $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_service_id);
      if ($negotiator->applies()) {
        $negotiator->run();
      }
    }
  }
}

timmillwood Thu, 14/12/2017 - 09:29 Tags drupal planet drupal-planet drupal8 Add new comment

Abgas-Skandal: Unzulässige Abschalteinrichtung im VW Touareg – KBA verordnet Rückruf

heise online Newsticker - 14. Dezember 2017 - 11:15
Die Halter von 25.800 VW Touareg erhalten demnächst Post von VW. Ihre Autos sollen eine neue Motorsoftware bekommen.

Apple will Aktionärsanträge zu Klimaschutz und Menschenrechten streichen

heise online Newsticker - 14. Dezember 2017 - 11:00
Der iPhone-Konzern hat bei der US-Börsenaufsicht SEC angefragt, weitere Aktionärsanträge blockieren zu dürfen, in denen unter anderem die Einrichtung eines Menschenrechtsausschusses gefordert wird.

Der Tod kommt per E-Mail: Erpresser drohen mit Mordanschlag

heise online Newsticker - 14. Dezember 2017 - 11:00
Wer dieser Tage Mail von einem Auftragskiller bekommt, der ist höchstwahrscheinlich Ziel eines besonders dreisten Betrugsversuchs geworden. Opfer sollten auf die Erpressung nicht eingehen und stattdessen die Polizei verständigen.

Turi Create: Apples Machine-Learning-Framework wird Open Source

heise online Newsticker - 14. Dezember 2017 - 10:00
Das Framework soll den Einsatz von maschinellem Lernen vereinfachen, unter anderem zur Erkennung von Objekten auf Bildern – aber auch zur Analyse von Texten und Daten aus Bewegungssensoren.

Elektro-Lkw: Pepsico bestellt 100 Tesla Semi

heise online Newsticker - 14. Dezember 2017 - 10:00
Für den seit Kurzem reservierbaren Elektro-Lkw sollen bisher 267 Vorbestellungen eingegangen sein. Ein Großteil davon stammt von Pepsico und Anheuser-Busch.

AMDs Mega-Treiberupdate Radeon Adrenalin Edition: Grafikkarte per Handy auslesen, verbesserte 3D-Funktionen

heise online Newsticker - 14. Dezember 2017 - 10:00
Hardware-Infos und Bildraten übers Smartphone auslesen, Chat beim Live-Streaming einblenden, während des Spielens Grafikeinstellungen setzen und mehr: Das jährliche Treiber-Generationsupdate bringt viele neue Funktionen für Nutzer von Radeon-Grafikkarten.

Seven – The Days Long Gone angespielt: Schleichend durch die Endzeit

heise online Newsticker - 14. Dezember 2017 - 9:30
Schleichen, kämpfen, klettern. Seven: The Days Long Gone von Fool’s Theory überrascht mit einem cleveren Mix aus Schleichabenteuer, Action-Rollenspiel und Parkour-Akrobatik. Ein tolles Konzept, dem es aber am Feinschliff fehlt.

Paydirekt: Paypal-Konkurrent der Banken bekommt einen neuen Chef

heise online Newsticker - 14. Dezember 2017 - 9:00
Der von den deutschen Banken und Sparkassen aufgesetzte Bezahldienst kommt nicht richtig in Fahrt. Ein neuer Chef mit einschlägiger Erfahrung soll es nun richten und muss dabei Widerstände bei den eigenen Gesellschaftern überwinden.

FHIR: Nur ein weiterer Standard oder die Zukunft im Gesundheitssektor?

heise online Newsticker - 14. Dezember 2017 - 8:30
Im Gesundheitsbereich kommunizieren noch immer viel zu wenige Anwendungen miteinander, von den aufkommenden Fitness-Apps ganz zu schweigen. Der neue Standard FHIR soll das Chaos beenden.

Elektroindustrie: Smart TVs haben sich in den Haushalten etabliert

heise online Newsticker - 14. Dezember 2017 - 8:00
63 Prozent der Fernsehzuschauer sehen sich laut einer Umfrage Inhalte aus dem Netz über das TV-Gerät an, über PC oder Laptop tun das 37 Prozent der Befragten.

Fallout 4 VR im Livestream: Mit der Vive im Wasteland unterwegs

heise online Newsticker - 14. Dezember 2017 - 7:00
c't-Redakteur Jan-Keno Janssen stellt sich heute nur mit einer Vive bewaffnet den Herausforderungen der Postapokalypse in Fallout 4 VR. Der Livestream startet um 16 Uhr. Übrigens: Das Spiel läuft auch mit Oculus Rift, allerdings nicht wirklich rund.

myDropWizard.com: CiviCRM secrets for Drupalers: Email Campaigns

Planet Drupal - 14. Dezember 2017 - 4:14

We're Drupalers who only recently started digging deep into CiviCRM and we're finding some really cool things! This series of videos is meant to share those secrets with other Drupalers, in case they come across a project that could use them. :-)

Most Drupalers at one time have had to deal with either sending e-mail newsletters directly from Drupal, or integrating with a 3rd party tool like Mailchimp or Constant Contact.

CiviCRM has built in e-mail newsletter functionality, and if you add to it the WYSIWYG e-mail builder Mosaico you can build really rich, responsive e-mail campaigns!

Watch the video here:

Video of CiviCRM secrets for Drupalers #1: E-mail Campaigns

Some highlights from the video:

  • A sneak peek at Round Earth: our project that bundles Drupal 8 + CiviCRM
  • Drupal 8 + CiviCRM vs. "only" Drupal
  • A quick walk-through on how to quickly and easily create an email campaign
  • Plus, we mention a couple of current "gotchas" that could save you frustration!

Please leave a comment below!

FFW Agency: The ABC's of Drupal: Region, Revision, Role

Planet Drupal - 14. Dezember 2017 - 2:03
The ABC's of Drupal: Region, Revision, Role Ray Saltini Thu, 12/14/2017 - 00:03

For anyone who's ever looked up a definition of a Drupal term and still wondered what it means, here are some practical explanations you can use to navigate the Drupal-verse. This is the latest in a series on Drupal-specific terminology.

Region

Regions divide Drupal pages into different sections. Each section contains information that determines the positions of various elements. These elements can include menus, headers, footers, and sidebars. The elements in each Region are called Blocks. (For more information on Blocks, see Aliases, Blocks, and Content Types.)

A Drupal site's active theme keeps information on the number, name, and location of each Region. Different themes can have different Regions. Typically, administrative themes have fewer regions spaced in wide columns across a page. The themes that face a site's end-users often have more complex layouts, which means more Regions. (To learn more about Themes, see Article, Base Theme, Content.

 

Together, Blocks and Regions make up Drupal's core's primary layout functionality. This combination is a simple yet powerful solution that has been steadily expanded with each major version of Drupal. 

As a note: Drupal Regions can be overridden by contributed modules such as Panels. Regions can also be overridden by custom page templates that apply to specific URLs or URL alias patterns. While the use of Panels can increase overhead and complexity, it makes additional layouts and landing page capabilities available to site builders. Layouts made with Panels are saved in the site's database, which mitigates the risk of rolling custom code by editing a site's theme files.

Revision

A Drupal Revision is a saved version of a set of changes to a piece of Drupal content created with a Content Entity. Revisions apply to any piece of content on a site, including Articles, Basic Pages, and custom content types.

After a piece of content is created, any changes or updates made to the content are saved in new versions, or Revisions. Drupal does this rather than editing an existing published version. These versions are stored indefinitely each time a set of changes is saved, and can be found on a content item's administrative interface. Users can save revisions in unpublished draft form, to be published at a later date. Previous versions can also be republished, which allows content authors to revert content to an earlier state.

Drupal's core revision feature supports a powerful workflow functionality that can be custom-configured to align with an organization's processes for content approval. Revision functionality can also be extended with the contributed Diff module to highlight changes between various drafts.

Role

Roles assign various permissions to a Drupal site's users. This includes the ability to edit and manage content and configure settings. Roles are typically grouped into sets of permissions that are determined by a user's expertise in the organization. A Role is a user-defined set of permissions that can be granted to groups of individuals. Typical Drupal user roles include Administrator (preconfigured), Content Creator, and Content Manager.

Anonymous and Authenticated are two special preconfigured user states that are accessed through the user administrative pages. Anonymous users are typically granted only the most basic permissions. By definition, Authenticated users are those that are known to the system. Authenticated users have an account and unique email address that associated with a cookie that resides locally in their browser.

When new functionality is added to Drupal, additional permissions are typically added to the system. These permissions can then be assigned to new or existing roles.

What Next?

If you've got questions about specific Drupal terms, let us know. Drop a request for a definition in the comments and we'll add it to our next ABCs of Drupal post. 

Comments

Bundesrechnungshof regt höhere Diesel-Besteuerung an

heise online Newsticker - 13. Dezember 2017 - 22:15
Durch die im Verhältnis zu Benzin geringere Besteuerung sind laut Bundesrechnungshof dem Fiskus 2015 Einnahmen in Höhe von 8 Milliarden Euro bei der Energiesteuer sowie 1,5 Milliarden Euro bei der Umsatzsteuer entgangen,

Elevated Third: Drupal 8 Is Great: Ambitious Digital Experiences Infographic

Planet Drupal - 13. Dezember 2017 - 20:04
Drupal 8 Is Great: Ambitious Digital Experiences Infographic Drupal 8 Is Great: Ambitious Digital Experiences Infographic Judd Mercer Wed, 12/13/2017 - 11:04

Customer experience. Data-driven marketing. Unified customer data. Digital transformation. You’ve heard the buzzwords and have a laundry list of things you’re not doing—or struggling to do—with an older version of Drupal. Enter Drupal 8. 

Digital Transformation is tough—and only getting tougher. 

Across the board, enterprise companies (and their digital marketing teams) struggle with technology platforms and integration in an effort to stay nimble.

Customer experience is at the top of every marketer’s list, and demand for ROI is growing. And it’s only going to continue.

Sound familiar? 

Technology should support digital transformation. But older versions of Drupal can be the biggest hindrance. Think back to your brainstorms and team meetings.

Do any of these statements sound familiar? 
  • We spend too much time managing content and not enough time producing it.
  • We spend too much money on developers to make simple site updates.
  • We have so much inefficiency with our disconnected systems.
  • We can’t seem to optimize or evolve out of our current situation.
  • We seem a long way off from personalization or targeting.

 

Drupal 8 is here. And it is the answer to all of the issues listed above. The improvements to the platform help users leverage personalization, integrate better and update seamlessly. Check out this infographic for more. 

 

 

Zahlen, bitte! 12 – Die erhabene Teilerin küsst in 3D

heise online Newsticker - 13. Dezember 2017 - 19:30
Die Zahl 12 bestimmt unser Leben: Sie teilt Jahre in Monate, Tage in 2 × 12 Stunden, sie besitzt sogar eigene Sprichwörter und wegen ihr geriet sogar Isaac Newton in einen Streit.

LattePanda-Boards Alpha und Delta: Mehr Rechnenpower und Linux

heise online Newsticker - 13. Dezember 2017 - 18:30
Die Rechenpower des MacBooks in Bastelrechnergröße verspricht Lattepanda mit seinen neuen Boards Alpha und Delta. Die Crowdfunding-Kampagne für die chinesischen Windows-Kleinstrechner ist kurz nach dem Start bereits erfolgreich finanziert.

KI-Konferenz: Programm der Minds Mastering Machines ist online

heise online Newsticker - 13. Dezember 2017 - 18:30
Ab sofort können sich Interessierte für die Fachkonferenz zu den Themen Machine Learning und künstliche Intelligenz registrieren, die im April in Köln stattfindet und sich in erster Linie an Softwareentwickler, Data Scientists und Forscher richtet.

Hackergruppe MoneyTaker erbeutet 10 Millionen US-Dollar von über zwanzig Banken

heise online Newsticker - 13. Dezember 2017 - 18:30
Die Gruppe MoneyTaker soll seit 2016 erfolgreich Banken in England, den USA und Russland attackieren. Jetzt ist sie in das Visier von Sicherheitsforschern geraten.