Drupal

My Test 1

New Drupal Modules - 19 February 2018 - 5:20am
Categories: Drupal

qed42.com: Implementing #autocomplete in Drupal 8 with Custom Callbacks

Planet Drupal - 19 February 2018 - 3:59am
Implementing #autocomplete in Drupal 8 with Custom Callbacks Body

Autocomplete on textfields like tags / user & node reference helps improve the UX and interactivity for your site visitors, In this blog post I'd like to cover how to implement autocomplete functionality in Drupal 8, including implementing a custom callback

Step 1: Assign autocomplete properties to textfield

As per Drupal Change records, #autocomplete_path has been replaced by #autocomplete_route_name and #autocomplete_parameters for autocomplete fields ( More details -- https://www.drupal.org/node/2070985).

The very first step is to assign appropriate properties to the textfield:

  1. '#autocomplete_route_name':
    for passing route name of callback URL to be used by autocomplete Javascript Library.
  2. '#autocomplete_route_parameters':
    for passing array of arguments to be passed to autocomplete handler.
$form['name'] = array( '#type' => 'textfield', '#autocomplete_route_name' => 'my_module.autocomplete', '#autocomplete_route_parameters' => array('field_name' => 'name', 'count' => 10), );

Thats all! for adding an #autocomplete callback to a textfield. 

However, there might be cases where the routes provided by core might not suffice as we might different response in JSON or additional data. Lets take a look at how to write a autocomplete callback, we will be using using my_module.autocomplete route and will pass arguments: 'name' as field_name and 10 as count.

Step 2: Define autocomplete route

Now, add the 'my_module.autocomplete' route in my_module.routing.yml file as:

my_module.autocomplete: path: '/my-module-autocomplete/{field_name}/{count}' defaults: _controller: '\Drupal\my_module\Controller\AutocompleteController::handleAutocomplete' _format: json requirements: _access: 'TRUE'

While Passing parameters to controller, use the same names in curly braces, which were used while defining the autocomplete_route_parameters. Defining _format as json is a good practise.

Step 3: Add Controller and return JSON response

Finally, we need to generate the JSON response for our field element. So, proceeding further we would be creating AutoCompleteController class file at my_module > src > Controller > AutocompleteController.php.

<?php namespace Drupal\my_module\Controller; use Drupal\Core\Controller\ControllerBase; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Drupal\Component\Utility\Tags; use Drupal\Component\Utility\Unicode; /** * Defines a route controller for entity autocomplete form elements. */ class AutocompleteController extends ControllerBase { /** * Handler for autocomplete request. */ public function handleAutocomplete(Request $request, $field_name, $count) { $results = []; // Get the typed string from the URL, if it exists. if ($input = $request->query->get('q')) { $typed_string = Tags::explode($input); $typed_string = Unicode::strtolower(array_pop($typed_string)); // @todo: Apply logic for generating results based on typed_string and other // arguments passed. for ($i = 0; $i < $count; $i++) { $results[] = [ 'value' => $field_name . '_' . $i . '(' . $i . ')', 'label' => $field_name . ' ' . $i, ]; } } return new JsonResponse($results); } }

We would be extending ControllerBase class and would then define our handler method, which will return results. Parameters for the handler would be Request object and arguments (field_name and count) passed in routing.yml file. From the Request object, we would be getting the typed string from the URL. Besides, we do have other route parameters (field_name and Count) on the basis of which we can generate the results array. 

An important point to be noticed here is, we need the results array to have data in 'value' and 'label' key-value pair as we have done above. Then finally we would be generating JsonResponse by creating new JsonResponse object and passing $results.

That's all we need to make autocomplete field working. Rebuild the cache and load the form page to see results.

PURUSHOTAM RAI Mon, 02/19/2018 - 17:29
Categories: Drupal

Multisite User Register

New Drupal Modules - 19 February 2018 - 3:13am
Categories: Drupal

Next Previous Post View link

New Drupal Modules - 19 February 2018 - 3:05am

I have developed a Drupal 8 module and named it "Next and previous link" The Drupal plug-in will allow the website visitors to jump on the next or previous post without going back to the main page to see all the posts. Drupal developers can use this plug-in for particular content types. Suppose, there are many large content bundles, then the developer can apply the plug-in for a specific bunch of content.

To understand how this plug-in will work, you can click on the following link.

Categories: Drupal

NoSQL Comments

New Drupal Modules - 19 February 2018 - 1:46am

No SQL Comments

Categories: Drupal

itsme

New Drupal Modules - 19 February 2018 - 1:38am

Authenticating on Drupal websites with itsme.

Categories: Drupal

Manifest file

New Drupal Modules - 19 February 2018 - 12:57am

The web app manifest is a simple JSON file that gives you, the developer, the ability to control how your app appears to the user in areas where they would expect to see apps (for example, a mobile device's home screen), direct what the user can launch, and define its appearance at launch.

Web app manifests provide the ability to save a site bookmark to a device's home screen. When a site is launched this way:

Categories: Drupal

jmolivas.com: Try Drupal 8.5 and umami profile using one command

Planet Drupal - 19 February 2018 - 12:23am
Try Drupal 8.5 and umami profile using one command jmolivas Mon, 02/19/2018 - 08:23 Body

If you are following the upcoming release of Drupal 8.5 you might be aware of the umami profile. This installation profile is part of the Out of The Box experience initiative. The goal of this profile is to add sample content presented in a well-designed theme, displayed as a food magazine. Using recipes and feature articles this example site will make Drupal look much better right from the start and help evaluators explore core Drupal concepts like content types, fields, blocks, views, taxonomy, etc.

Categories: Drupal

Phones - phonebook

New Drupal Modules - 18 February 2018 - 11:36pm
Categories: Drupal

Entity Type Clone

New Drupal Modules - 18 February 2018 - 11:33pm

Entity Type Clone allows Administrator to clone Content types and Vocabularies.
These will be used in creating an additional entity type with existing one.

Categories: Drupal

Roy Scholten: Tweets starting from here

Planet Drupal - 18 February 2018 - 2:55pm
18 Feb 2018 /sites/default/files/styles/large/public/20180219-notes-ui.png?itok=Xp6Vepyy Tweets starting from here

My previous post inspired Joeri to some improvements on his site. Nice!

I built another step towards POSSE this weekend: tweet-sized notes posted as content on yoroy.com that get pushed to Twitter via RSS and Zapier. Here’s how:

Create a new content type “Note”. This one needs to only have a text area. And here we run into Drupal always requiring a title. We can’t create entities without giving it a title. The title itself is always a text field, so not ideal for writing 280 char bits of text. Two contrib modules to work around this:

  • Auto entity label to define an automatic pattern for the title of these Notes. I set it to use a simple timestamp.
  • Exclude node title to actually hide the title field on the Note creation form and on display.

Next I defined a new text format that does not use CKEditor but allows tags and automatically transforms URLs into links. I set this to be the default text format for the text area on the Note using the Better Formats module (sadly currently only available as an old development release). This step is optional, it helps remove user interface clutter. This gives me a content creation form with just a single plain text text area, a “published” checkbox and a Save button.

I updated the views that list blog content on this site to also include content of type “Note” and configured a Notes RSS feed as well. I use this feed as an input on Zapier where the Notes body is extracted and posted as a tweet.

Tags posse twitter Drupal content modeling drupalplanet
Categories: Drupal

Page hits

New Drupal Modules - 18 February 2018 - 5:12am
Categories: Drupal

User route context

New Drupal Modules - 17 February 2018 - 2:17pm

Drupal core provides only user context for current_user.
At this moment it is impossible to use contexts to get user based on URL parameters (like possible with nodes).

This module solves the issue by providing new user context.

Categories: Drupal

Image catcher

New Drupal Modules - 17 February 2018 - 2:15pm
Summary Introduction:

Image catcher is a services provider which allows you to create images files from external URL or base64 source.

Categories: Drupal

Field Group Modal Bootstrap

New Drupal Modules - 17 February 2018 - 12:52pm

This module provides a modal Bootstrap window from field group elements.

Dependencies
Categories: Drupal

Mailchimp Simple Signup

New Drupal Modules - 17 February 2018 - 9:32am

Simple Mailchimp signup that delegates early to Mailchimp and focuses on display options.
No API key here, just some very basic use cases for a call to action.

For more advanced use cases, use the Mailchimp or Simple Mailchimp modules.

Categories: Drupal

Matt Glaman: Florida Drupal Camp: a return four years in the making

Planet Drupal - 17 February 2018 - 4:25am
Florida Drupal Camp: a return four years in the making mglaman Sat, 02/17/2018 - 06:25

Five years ago I went to my second Drupal Camp and first Drupal Camp that I presented at. It has been four years, but I am finally going back to Florida Drupal Camp. I am pretty excited, as a lot has changed since then.

Categories: Drupal

Update Manager Advanced

New Drupal Modules - 17 February 2018 - 4:05am
Categories: Drupal

Update Manager Advice

New Drupal Modules - 17 February 2018 - 4:00am
Categories: Drupal

Update More Details

New Drupal Modules - 17 February 2018 - 3:56am
Categories: Drupal

Pages

Subscribe to As If Productions aggregator - Drupal