1

I am trying to add a custom ctools selection plugin for entity reference field as explained Here but it is never bing called but it is calling the parent class (EntityReference_SelectionHandler_Generic). Following is my code.

1) Implements hook_ctools_plugin_directory

function mymodule_ctools_plugin_directory($module, $plugin) {

   if ($module == 'entityreference') {
    dsm($plugin);
    return 'plugins/' . $plugin;
  }
 }

Than I created "plugins/selection" folder in my module directory following is the code I have in this file respectively-

1) Base.inc

$plugin = array(
'title' => t('Simple (with optional filter by bundle)'),
'class' => 'myClass',
'weight' => -100,
);

2) myClass.class.php

class myClass extends EntityReference_SelectionHandler_Generic{
public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
watchdog('getInstance', "print something for test ");
return new ExampleSelectionHandler($field, $instance, $entity_type,  $entity);

} public function buildEntityFieldQuery($match = NULL, $match_operator =CONTAINS'){ } }

But Myclass is never getting called instate it is calling the parent class(I have added a watchdog in that class).

1

same problem, two days wasted according to http://lookalive.co.uk/blog/drupal-entity-reference-how-make-custom-entity-reference-selection-handler and all it's copies.

entityreference_get_selection_handler() code dpm() showed that "*.inc" should be named 'base.inc' as in your case.

After renaming in my case *class.php started to execute.

So all i can advice to you - check if module has higher weight than 'entityreference' module, see here https://www.drupal.org/node/110238

And add the first line to '*class.php' (for inheritance)

require_once drupal_get_path('module', 'entityreference') . '/plugins/selection/EntityReference_SelectionHandler_Generic.class.php';

If this helped to you - pleace vote [+] this answer (i need more scores, tks)

  • Hi, Mykola, Thanks for your answar, but I already managed this using some other codes. Anyways adding [+] – Nabajit Roy Jul 4 '16 at 16:21
  • Thanks. Me to managed with this in way described above. Anyway the question how to proper feed the plugin to ctools entityselector remains open, i assume. May be the difference to manual or OgExampleSelectionHandler is in that they consider widget for field provided by same module that is declarating the SelectionHandler class. Anyway i move to other tasks – Mykola Mykolayovich Dolynskyi Jul 4 '16 at 16:44
  • do you have any ideas on this- drupal.stackexchange.com/questions/205506/… – Nabajit Roy Jul 4 '16 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.