Inhalt abgleichen
Drupal.org - aggregated feeds in category Planet Drupal
Aktualisiert: vor 15 Minuten 19 Sekunden

Mediacurrent: Accommodating Drupal In Your Components

15. Februar 2018 - 18:44

Last fall at BADCamp it was exciting to see that a component-driven approach to building Drupal 8 themes is becoming the standard. Many people are doing great things to advance this approach, including reducing duplication and simplifying data structures. In the day-long front end summit, and in many sessions and BOFs during BADCamp, great tips were shared for making the most of helper modules, such as the UI Patterns module, as well as techniques that make the most of Pattern Lab, KSS, and other front end systems.

Aten Design Group: Using Sub-profiles and Build Tools to Start Your Next Drupal 8 Project

15. Februar 2018 - 18:37

In the past I’ve struggled with the decision of whether or not to start a new Drupal project with a distribution. Since Drupal 8 has evolved I’ve noticed the decision has shifted from whether or not to use one, to which one is the right fit. Two things that are fairly new to distributions are sub-profiles and build tools, both of which have influenced the way I approach a new Drupal project.

Sub-profiles

Sub-profiles are a relatively new thing. While there is still some work to be done in how to manage dependencies and deal with more complex inheritance, inheriting a profile is now possible and in many cases recommended. One example is Acquia's Lightning distribution. Lightning does a good job highlighting the wheels you should not be re-inventing, while also serving as an example of a parent and sub-profile to the well known OpenEDU distribution.

Acquia's article about sub-profiles covers a helpful list of questions to start with such as: Does your new Drupal 8 site need media support? Does it need layout support? As the project develops and matures, are you ready to support the changes that will happen in Drupal core with media and layout, or anything else? As of version 8.3, things like media and layout were only stable enough in contrib, and in 8.4 were only partially moved into core. As of 8.5 and 8.6, workflow, media and layout are planned to be moved into core and stable and will considerably change your site's architecture and implementation. So, with a sub-profile, the specifications for which modules to use and how to use them are now inherited, and not the responsibility of the sub-profile.

Build tools

The next thing to consider is how, or who, is actually building your profile. If you're not thinking about SaaS, (if you are, see Dries's article about making distributions commercially interesting), then you're really targeting developers. Since Drupal 8 development is now entirely composer based, you might want to checkout what profiles are already doing with composer. Here are some examples of composer.json configurations as well as open source tools that you can integrate with composer:

  • Composer scripts - https://github.com/acquia/lightning/blob/8.x-3.x/composer.json - script hooks, (like post-install, pre-install), auto class loading, dependency management, etc.
  • Robo task runner - https://github.com/consolidation/Robo - defines tasks in an auto-loaded PHP class RoboFile
  • Phing build tool - https://www.phing.info - define tasks with a build.xml
  • Testing - PHPUnit test helper methods and classes, as well as addon Behat features and commands
  • Starter content - this currently is just a hook_install script that installs a view with a header, but worth trying out and building on
  • TravisCI integration - with only a few modifications to an existing .travis.yml file you can setup continuous integration for your profile. The existing configuration already handles setting up your server, installing composer and configuring PHP, installing a local browser for testing, headless browser for testing (see composer hooks), installing and re-installing Drupal (see robo), running tests (see behat, phpunit), and development tools for moving files around in your local development environment.

Using a combination of sub-profiles with these build tools have made starting my new Drupal projects more efficient. There is a lot of helpful material out there to learn from, contribute to, and build on. Hopefully this gives you a great start to focusing your new Drupal projects as well.

Amazee Labs: Agile Agency Survey Roundup

15. Februar 2018 - 16:15
Agile Agency Survey Roundup

Thanks again to everyone who has participated in my survey about agile practices in our industry. In this final piece, I would like to share some of my key observations and provide an overview of what has been covered in the previous nine blog posts.

Josef Dabernig Thu, 02/15/2018 - 15:15

The 30 survey participants provided in-depth answers in 10 different sections with a set of multiple-choice questions and freeform answers. The survey aimed to get a better understanding of how agile practices are established and live in agencies related to the Drupal community.

Survey results overview
  • Part 1 - Initial Observations provides an overview of popular methodologies, project team sizes, iteration length, team integration, how teams stay connected, splitting up the work, client communication and delivery practices.

  • Part 2 - Process Insights gives a deeper understanding of how strictly teams follow the process and which adaptations they have applied.

  • Part 3 - Teams analyses the average team size, where teams work and how teams and projects are paired.

  • Part 4 - Discovery & Planning examines the balancing features and functionality against providing value when talking about work increments and when teams make the discovery.

  • Part 5 - Team Communication & Process is about how teams communicate, how much time they spend in meetings and how client work is balanced against internal or non-billable work.

  • Part 6 - Defining Work analyses the different phases in the ticket process and who is involved in defining work, as well as which tools are essential for organising the work.

  • Part 7 - Estimations provides insights into how teams estimate and by whom estimations are executed.

  • Part 8 - Client Interactions highlights how regularly teams meet with the client and how communication between the team and the client is handled.

  • Part 9 - Practices gives a rundown of how often teams deploy code and compares usage of the various agile practices teams apply to their work.

Key survey takeaways

Having spent some time looking at the data, and processing chunks of the results into the individual blog posts I have mentioned before, was a rewarding task. Even though the number of survey participants was not very high, I believe that the results are appropriate and representable. Apart from the quantitative analysis, I was happy to have asked for freeform answers which provided me with the diversity to allow the survey to be representative.

There is not a single truth to how agile works. In some cases, you'll be able to collaborate closely with the client on a daily basis, in other cases, you will be lucky if you can meet the client every second week. While some agencies have fewer long-term projects, the majority have a mix of smaller and bigger projects regarding size and duration.

Some teams prefer to work integrated across disciplines. Others prefer to have separate teams based on their expertise. From my point of view, active collaboration and communication between teams and clients are essential to create a better product. The way in which this is organised always depends on what works best for the participating individuals and organisations.

An example, where implementing a rigid process can make sense, would be, that we can help the team not to take on too much work. On the other hand, if the process starts getting in the way of everything, we need to remind ourselves of the principle «Individuals and interactions over processes and tools» of the agile manifesto. The process is there to help the team collaborate with the client to produce working software and responding to change as we move forward in the project. The process must be well understood by all role players so that it helps instead of limit our work.

Feel free to dig into the results raw data and please make sure to look at the freeform answers. I tried to summarise some highlights as parts of the series, but there is a lot more to be found from reading them yourself.

That’s it for the agile agency survey results. Thanks again to all the participants and let us know if you have any thoughts on the survey about agile practices.

myDropWizard.com: CiviCRM secrets for Drupalers: Screencast of Roundearth CiviCRM Profile Forms

15. Februar 2018 - 15:01

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. :-)

In the screencast below, I'll demonstrate how to create a publicly accessible CiviCRM "lead" form. This form will add a contact into your CRM database. In this example, I'll be creating a "Corporate Sponsor Lead" type of form. This is the sort of form you might put into a newsletter email or just have easily accessible by volunteers.

Watch the screencast to see if I run into any issues with the instructions:

Video of CiviCRM secrets for Drupalers: Screencast of Roundearth CiviCRM Profile Forms

Some highlights from the video:

  • Create a CiviCRM Profile with a "Corporate Sponsor Lead" Form
  • Create a ACL to allow this Profile Form to be public

Please leave a comment below!

iterate.: Iterate Presents 5 Minutes - January

15. Februar 2018 - 13:12

To kick off 2018 we had our first round of these 5 minute presentations in January. We learned about Why Typography Matters, competing at SEO, Drupal 8 templates, Mental Fitness for Business, and When to Apologise.

Vardot: Interview with Omar Alahmed, the First Acquia Certified Drupal 8 Backend / Developer in MENA

15. Februar 2018 - 12:27
Ahmed Jarrar February 15, 2018

 

Omar Alahmed is a Technical Team Lead at Vardot with more than 10 years experience in web development, specializing in PHP and Drupal. Omar has worked with Drupal since 2007 starting with Drupal 5 and has continued along mastering 6, 7, and Drupal 8.

 

Omar had multiple motivations to earn certifications, which serve to establish his credibility and expertise. He has achieved Zend Certified PHP Engineer in Sep 2013, Oracle Certified Professional (OCP) MySQL 5.6 Developer in May 2014, Acquia Certified Developer - Drupal 7 in Dec 2014, and most recently, Acquia Certified Developer - Drupal 8 in Jan 2018 and Acquia Certified Back End Specialist - Drupal 8 in Feb 2018.

 

More importantly, is the added benefit of the time spent reviewing and studying all of the relevant topics and materials that these qualifications are built upon. His deep study of computer science concepts allowed him to step beyond surface-level theory and apply his learnings directly in his application of the code.

We interview Omar about what excites him most working with enterprise Drupal implementations at Vardot.

 

What are the tasks you find most exciting?

I started as a full-stack developer and I always feel that it is the best role for a new web developer. This is because it will introduce you to the broadest view of the web development life-cycle process. Taking this approach will give you exposure and the opportunity to examine what is needed in each phase. However, after getting the needed experience, some tasks may distract you from the deeper technical items. Therefore, I currently prefer to work on more custom tasks, such as using APIs and custom module development.

 

At Vardot, we follow the Agile methodology in our project development life-cycle. This usually begins with a Work Breakdown Structure (WBS), dividing the project deliverables into small chunks, and then assigning them to project’s team members. I prefer to work on the more customized tasks, either on the backend or frontend and to guide and train other team members when needed. For our team, this helps us deliver the tasks in a formalized practice and ensures projects to follow the Drupal best-practices, thus contributing to the Drupal project more often in each project.

 

How did you prepare for the exams? What background knowledge does one need to get Acquia Drupal 8 Developer & Acquia Back End Specialist Certified?

When I received the Acquia Certified Developer - Drupal 7 certification, I realized that the exam truly validates a Drupal developer experience in mastering a Drupal website in a professional and standardized way. It is not a theoretical exam and cannot be passed simply by reading a study guide. Practical experience in developing web applications, like the work I do at Vardot, is required to succeed.

 

At Vardot we always strive to follow and endorse the best practices in development and apply it to different types of projects. Given this experience, I didn't find any difficulties during the preparation for the exam. I made sure to review the study guide links that were provided by Acquia and found ways to programmatically apply the topics that I had not worked with before. This allowed me to apply these topics in action instead of only reading about them.

 

Anyone pursuing this certification would probably agree that programming is an experimental science. In order to obtain the reusable knowledge at hand, you must write code and repeatedly practice. This method will help you expose problems that you may not be been introduced to before. I found that the published Acquia documentation is a good start for module development, as well as the Drupal API documentation.

 

Particularly:

Coding Standards: https://www.drupal.org/docs/develop/standards

Block API: https://www.drupal.org/docs/8/api/block-api

Form API: https://www.drupal.org/docs/8/api/form-api

Cache API: https://www.drupal.org/docs/8/api/cache-api/cache-api

Routing API: https://www.drupal.org/docs/8/api/routing-system

Theming API: https://www.drupal.org/docs/8/theming

 

Don't panic if you don't have an enjoyable experience in the Drupal API or module development resources. The key takeaway is to get an overview of the topics and then apply as much as you can.

 

Preparing using the above material is very important for both the Developer and Back End Specialist exams. The Developer exam covers advanced topics, but it also encompasses site building skills, such as working with content types, blocks, taxonomies, and views.

 

The Back End Specialist exam touches everything about Drupal API, performance, security, contributing to the community, and how to apply these techniques in real tasks by giving real scenarios or problems and asking to resolve them in the best way. So make sure to understand Drupal 8 core’s structure, and to do more hands-on practices before taking the exam, especially if you are not familiar with the latest PHP and OOP development techniques such as design patterns.

For further information about the content of the exams, you can check out the study guides for Acquia certification exams and an overview of Acquia Certification Program.

 

What are some tips you would give other developers working on Drupal 8?

As a Drupal 8 developer, you have probably observed that the Drupal community is the most important factor that places Drupal as the top web development platform. Therefore, I would say to try to interact with the community members; don’t work alone, don’t repeat yourself, and be cooperative as much as possible. If you find a bug or need a new feature, feel free to create a new issue in the project. You can also resolve, test and patch it to enable all Drupalers around the world to benefit along with you.

 

You’re probably aware that Drupal 8 is built on top of many Symfony2 components, like DependencyInjection, EventDispatcher, and Routing, with some customizations to be suitable for Drupal needs. With that in mind, it's a good idea for you to traverse how the core uses these components in order to facilitate and speed up your Drupal development. It’s important to always use the Drupal core code as an example if you need to write custom code because it will illustrate the best way to proceed and enlighten you what APIs are available for use. This helps you learn by example.

 

Summary

Omar Alahmed gives us a great example of what it takes to demonstrate success as a specialized developer in the Drupal community. Through his exhibited certifications, we can assume Omar's background required many dedicated hours of hard work and study. But we can also see that he was preparing for more than just certifications. Omar shows a passion for web development community at large, offering his advice as a team lead on what it takes to be a successful team player. His method of approaching problems and finding new ways to create solutions using industry best practices and established patterns makes Omar an invaluable member of our development team at Vardot.

frobiovox.com: Rearchitecting for Drupal 8; a DrupalCon Session

15. Februar 2018 - 2:00
Rearchitecting for Drupal 8 This is an export of my session from DrupalCon Baltimore 2017. This is here for posterity. The least effor possible was put into trascribing it from presentation format to a web page. In case you are wondering Hello My Name Is Frank I am a Christian, Father, and Technology Enthusiast. Online my name is frob (IRC, d.o, github) On Twitter I am @frobdfas My Blog is...

myDropWizard.com: Drupal 6 security update for Custom Permissions!

15. Februar 2018 - 0:57

As you may know, Drupal 6 has reached End-of-Life (EOL) which means the Drupal Security Team is no longer doing Security Advisories or working on security patches for Drupal 6 core or contrib modules - but the Drupal 6 LTS vendors are and we're one of them!

Today, there is a Moderately Critical security release for the Custom Permissions module to fix an Access Bypass vulnerability.

This module enables the user to set custom permissions per path.

The module doesn't perform sufficient checks on paths with dynamic arguments (like "node/1" or "user/2"), thereby allowing the site administrator to save custom permissions for paths that won't be protected. This could lead to an access bypass vulnerability if the site is relying on the Custom Permissions module to protect those paths.

After applying this patch, go to the "Site Configuration Permissions" page and click "Save". If the form saves without errors, your site isn't vulnerable. If you get an error, delete the permission or correct the patch per the information in the error.

See the security advisory for Drupal 7 for more information.

Here you can download the Drupal 6 patch.

If you have a Drupal 6 site using the Custom Permissions module, we recommend you update immediately! We have already deployed the patch for all of our Drupal 6 Long-Term Support clients. :-)

If you'd like all your Drupal 6 modules to receive security updates and have the fixes deployed the same day they're released, please check out our D6LTS plans.

Note: if you use the myDropWizard module (totally free!), you'll be alerted to these and any future security updates, and will be able to use drush to install them (even though they won't necessarily have a release on Drupal.org).

Roy Scholten: Drupal admin revamp UI research

14. Februar 2018 - 23:56
14 Feb 2018 /sites/default/files/styles/large/public/20180214-admin-revamp.png?itok=rK7Zzjiu Drupal admin revamp UI research

At Drupalcon Vienna there was a lot of interest and preparation work done around modernizing the Drupal administrative interface. I wrote up a high level summary here. As a result this initial issue was posted.

My previous post with a small concept for the editor UX triggered some interesting discussion on Twitter.

We also discussed this topic during yesterdays UX meeting.

As a result, ckrina now proposes an initial round of research to learn and get inspiration from other systems. Mind you, this is the woman that brought us the redesigned status report page and is a member of the team that made the Umami demo that’s now in core. Good things can come from this!

Your help in researching these topics is very welcome. Have a look.

Tags ui research Drupal drupalplanet

Flocon de toile | Freelance Drupal: Customize the order's activity log with Drupal Commerce 2

14. Februar 2018 - 23:00
By default, Drupal Commerce 2 provides an activity log on the life of each order: the add to cart event, the checkout entry, the order placed, its possible shipment and its conclusion. Each status of the command corresponds to an entry in a log that is generated. This provides a complete history for each order. This activity log is generated by a small module, developed by the maintainers of Drupal Commerce 2. A small but extremely powerful module, titled Commerce log. Let's discover how to use this module to insert additional log entries.

Brian Osborne: Using a Forked Package in Your Composer Project

14. Februar 2018 - 19:58

Sometimes you need to make custom modifications to a composer package. Assuming that your modification is a bug fix, the best approach is to file an issue with the package's issue queue and submit the fix as a pull request (or a patch file when dealing with Drupal projects). Then you can use the composer-patches plugin to include the change in your project.

Drupal Console: Drupal Console 1.6.0

14. Februar 2018 - 18:55

Drupal Console 1.6.0 is out. The newest release contains bug fixes one new command added to generate site alias. Improved UI/UX when listing commands within a namespace, debugging site alias and chain commands. Twig support added to chains commands.

Zoocha Blog: Extending Twig Templates with Blocks in Drupal 8

14. Februar 2018 - 17:49
Web Development Extending Twig Templates with Blocks...

One of the many good things about Drupal 8 is the introduction of Twig. It's a lovely templating engine that, in my opinion, is far superior to PHPTemplate. For us frontenders, it has a much nicer user syntax that's more akin to handlebars or other JS templating engines. Imagine this…

14 Feb 2018 Extending Twig Templates with Blocks...

Valuebound: How to generate PDF of HTML code in Drupal 8

14. Februar 2018 - 9:52

Have you ever been in a situation where you were required to generate PDF of HTML code? Recently, I came across a similar situation. In Drupal 8, there are several PHP libraries that allow you to generate PDF. However, out of curiosity, I thought of finding better alternatives. After some research, I found an interesting library, called mPDF, that converts HTML code to PDF without changing the structure.

mPDF is a smart library that considers the CSS attached to the HTML. Not only CSS, it takes care of almost all the HTML tags like form tags, tables, images, lists etc.

Generating PDF of HTML in custom module

Requirements

mPDF 7.0 requires PHP ^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0.…

Agiledrop.com Blog: AGILEDROP: Our blog posts from January

14. Februar 2018 - 8:55
You have already seen what Drupal blogs we trending in the previous month, and now it is time to look at all our blog post we wrote. Here are the blog topics we covered in January.   The first blog post in January was 2017 in review. In this blog post, our Commercial director Iztok looked back in the year 2017 and summarized what differences we made as a company, which Drupal events we have visited, how much fun we had and how do we contributed back to the community in 2017.    The second was Who will get the control of personal data after GDPR? by Ales Kohek. He talked about new set of… READ MORE

Commerce Guys: We're sponsoring and speaking at Florida DrupalCamp!

14. Februar 2018 - 5:38

Florida DrupalCamp 2018 finally arrives this weekend, February 16-18! Commerce Guys is a Gold sponsor this year, and I will be heading down to the conference to talk about Reporting in Drupal Commerce.

With Drupal Commerce 2.4 out the door (see yesterday's release notes), our focus is shifting back to the contributed module ecosystem. As Bojan highlighted in our year in review blog post, we have now ported many essential modules and pushed for them to achieve stable releases. With 55 payment gateways, shipping support, and work on recurring payments in progress, we've identified reporting as our next major initiative.

Reporting is obviously essential to eCommerce. Merchants need to know which products are selling, if a marketing campaign is producing new sales, how much sales tax to remit, and more. Each new type of report brings unique challenges related to understanding, querying, and visualizing the underlying data.

At Florida DrupalCamp, I will discuss the requirements and challenges we've identified in reporting within Drupal Commerce and the solutions available to our users in the Commerce Reports and Commerce Google Analytics modules. Finally, I will also unveil Commerce Guys’ newest product, Lean Commerce Reports.

Lean Commerce Reports, which we first showed off at DrupalCon Baltimore, is finally production ready. Over 80 stores use Lean Commerce Reports to add a plug and play sales dashboard to the back end of Drupal Commerce. The dashboard gives store owners immediate visibility into their sales trends, traffic by channel, conversion rate, and top selling products over time. Furthermore, each summary report on the dashboard links to a full report you can further explore, refine, export, etc.

Jonathan and I have worked really hard these last few months to get Lean Commerce Reports to where it is now, and I can't wait to show it off in Orlando. If you miss me there, come find us at DrupalCon Nashville or get in touch if you'd like to try it out while it's still in private beta.

Brian Osborne: Importing Images Within an RSS Feed Using the Drupal 7 Feeds Module

14. Februar 2018 - 4:58

Yes, a blog post about Drupal 7!

I recently worked on an enhancement for a large multi-site Drupal 7 platform to allow its users to import news articles from RSS feeds. Pretty simple request, and given the maturity of the Drupal 7 contrib module ecosystem, it wasn't too difficult to implement.

Brian Osborne: Importing Images Within an RSS Feed Using the Drupal 7 Feeds Module

14. Februar 2018 - 4:58

Yes, a blog post about Drupal 7!

I recently worked on an enhancement for a large multi-site Drupal 7 platform to allow its users to import news articles from RSS feeds. Pretty simple request, and given the maturity of the Drupal 7 contrib module ecosystem, it wasn't too difficult to implement.

PreviousNext: Creating a custom LinkIt matcher plugin

14. Februar 2018 - 3:27

In one of our recent projects, our client made a request to use LinkIt module to insert file links to content from the group module.  However, with the added distinction of making sure that only content that is in the same group as the content they are editing is suggested in the matches.

Here’s how we did it.

by Pasan Gamage / 14 February 2018 The LinkIt module

First, let me give you a quick overview of the LinkIt module.

LinkIt is a tool that is commonly used to link internal or external artifacts. One of the main advantages of using it is because LinkIt maintains links by uuid which means no occurrence for broken links. And it can link any type of entity varying from core entities like nodes, users, taxonomy terms, files, comments and to custom entities created by developers.

Once you install the module, you need to set a Linkit profile which consists of information about which plugins to use. To set the profiles use /admin/config/content/linkit path. And the final step will be to enable the Linkit plugin on the text format you want to use. Formats are found at admin/config/content/formats. And you should see the link icon when editing content item.

Once you click on the LinkIt icon it will prompt a modal as shown below.

By default LinkIt ships with a UI to maintain profiles that enables you to manage matchers.

Matchers

Matchers are responsible for managing the autoload suggestion criteria for a particular LinkIt field. It provides bundle restrictions and bundle grouping settings

Proposed resolution

To solve the issue; we started off by creating a matcher for our particular entity type. Linkit has an EntityMatcher plugin that uses Drupal's Plugin Derivatives API to expose one plugin for each entity type. We started by adding the matcher that linkit module exposed for our custom group content entity type.

We left the bundle restrictions and bundle grouping sections un-ticked so that all existing bundles are allowed so the content of those bundles will be displayed.

Now that the content is ready we have to let the matcher know that we only need to load content that belongs to the particular group for which the user is editing or creating the page.

Using the deriver

In order to do that we have to create a new class in /modules/custom/your_plugin_name/src/Plugin/Linkit/Matcher/YourClassNameMatcher.php by extending existing EntityMatcher class which derives at /modules/contrib/linkit/src/Plugin/Linkit/Matcher/EntityMatcher.php.

Because Linkit module's plugin deriver exposes each entity-type plugin with and ID for the form entity:{entity_type_id} we simply need to create a new plugin with an ID that matches our entity type ID. This then takes precedence over the default derivative based plugin provided by Linkit module. We can then modify the logic in either the ::execute() or ::buildEntityQuery method.

Using LinkIt autocomplete request

But here comes the challenge, in that content edit page the LinkIt modal doesn’t know about the group of the content being edited, therefore we cannot easily filter the suggestions based on the content being edited. We need to take some fairly extreme measures to make that group ID available for our new class to filter the content once the modal is loaded and user starts typing in the field.

In this case the group id is available from the page uri.

So in order to pass this along, we can make use of the fact that the linkit autocomplete widget has a data attribute 'data-autocomplete-path' which is used by its JavaScript to perform the autocomplete request. We can add a process callback to the LinkIt element to extract the current page uri and pass it as a query parameter in the autocomplete path.

The code

To do so we need to implement hook_element_info_alter in our custom module. Here we will add a new process callback and in that callback we can add the current browser url as a query parameter to the data-autocomplete-path attribute of the modal.

\Drupal\linkit\Element\Linkit is as follows;

public function getInfo() { $class = get_class($this); return [ '#input' => TRUE, '#size' => 60, '#process' => [ [$class, 'processLinkitAutocomplete'], [$class, 'processGroup'], ], '#pre_render' => [ [$class, 'preRenderLinkitElement'], [$class, 'preRenderGroup'], ], '#theme' => 'input__textfield', '#theme_wrappers' => ['form_element'], ]; }

Below is the code to add the process callback and alter the data-autocomplete-path element. We rely on the HTTP Referer header which Drupal sends in its AJAX request that is used to display the LinkIt modal, which in turn builds the LinkIt element

/** * Implements hook_element_info_alter(). */ function your_module_name_element_info_alter(array &$info) { $info['linkit']['#process'][] = 'your_module_name_linkit_process'; } /** * Process callback. */ function your_module_name_linkit_process($element) { // Get the HTTP referrer (current page URL) $url = \Drupal::request()->server->get('HTTP_REFERER'); // Parse out just the path. $path = parse_url($url, PHP_URL_PATH); // Append it as a query parameter to the autocomplete path. $element['#attributes']['data-autocomplete-path'] .= '?uri=' . urlencode($path); return $element; }

Once this is done we can now proceed to create the new plugin class extending EntityMatcher class. Notice the highlighted areas.

namespace Drupal\your_module\Plugin\Linkit\Matcher; use Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher; use Drupal\linkit\Suggestion\EntitySuggestion; use Drupal\linkit\Suggestion\SuggestionCollection; /** * Provides specific LinkIt matchers for our custom entity type. * * @Matcher( * id = "entity:your_content_entity_type", * label = @Translation("Your custom content entity"), * target_entity = "your_content_entity_type", * provider = "your_module" * ) */ class YourContentEntityMatcher extends EntityMatcher { /** * {@inheritdoc} */ public function execute($string) { $suggestions = new SuggestionCollection(); $query = $this->buildEntityQuery($string); $query_result = $query->execute(); $url_results = $this->findEntityIdByUrl($string); $result = array_merge($query_result, $url_results); if (empty($result)) { return $suggestions; } $entities = $this->entityTypeManager->getStorage($this->targetType)->loadMultiple($result); $group_id = FALSE; // Extract the Group ID from the uri query parameter. if (\Drupal::request()->query->has('uri')) { $uri = \Drupal::Request()->query->get('uri'); list(, , $group_id) = explode('/', $uri); } foreach ($entities as $entity) { // Check the access against the defined entity access handler. /** @var \Drupal\Core\Access\AccessResultInterface $access */ $access = $entity->access('view', $this->currentUser, TRUE); if (!$access->isAllowed()) { continue; } // Exclude content that is from a different group if ($group_id && $group_id != $entity->getGroup()->id()) { continue; } $entity = $this->entityRepository->getTranslationFromContext($entity); $suggestion = new EntitySuggestion(); $suggestion->setLabel($this->buildLabel($entity)) ->setGroup($this->buildGroup($entity)) ->setDescription($this->buildDescription($entity)) ->setEntityUuid($entity->uuid()) ->setEntityTypeId($entity->getEntityTypeId()) ->setSubstitutionId($this->configuration['substitution_type']) ->setPath($this->buildPath($entity)); $suggestions->addSuggestion($suggestion); } return $suggestions; } } Conclusion

And we are done.

By re-implementing the execute() method of EntityMatcher class we are now able to make the LinkIt field to display only content from the same group as the content the user is editing/creating.

So next challenge here is to create some test coverage for this, as we're relying on a few random pieces of code - a plugin, some JavaScript in the LinkIt module, an element info alter hook and a process callback - any of which could change and render all of this non-functional. But that's a story for another post.

Tagged Drupal 8, Drupal Modules, Custom modules