I've only got one relation type defined, that collects a custom entity type, but the collector shows me nodes and taxonomy terms that are being loaded on the current page.

Given the collector has a list of relation types, could it filter the list of entities to only those that are eligible to be added as endpoints in relations? It would simplify use of the collector widget, and presumably trying to add those will lead to an error.

Comments

chx’s picture

Category: bug » feature
joachim’s picture

I wasn't sure whether to call this a bug or a feature request, but I presume it can lead the user to try to add things that just produce an error -- hence a bit of a UI bug.

joachim’s picture

Category: feature » bug

Trying to add an entity that won't fit into the selected relation produces an AJAX error:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /system/ajax
StatusText: Service unavailable (with message)
ResponseText: Recoverable fatal error: Argument 2 passed to drupal_array_get_nested_value() must be an array, null given, called in modules/field/field.form.inc on line 369 and defined in drupal_array_get_nested_value() (line 6490 of includes/common.inc).

Can we call this a bug now?

chx’s picture

Yes :)

pyxio’s picture

Greetings,

I get the same error. Just letting you know. Cheers, Kevin

Uncle_Code_Monkey’s picture

I ran into this issue myself and created a patch for it. First time submitting a patch, so I hope it works.
I basically copy the previous IF section that filters endpoints based on defined source/targets and instead just run the same thing only on the defined sources (since there won't be any targets).

Uncle_Code_Monkey’s picture

Status: Active » Needs review
StatusFileSize
new993 bytes

Resubmitting patch because I needed to change the issue status to "needs review".

Status: Needs review » Needs work

The last submitted patch, relation-entity_collector_filter-1611752-6.patch, failed testing.

Uncle_Code_Monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new6.22 KB

After going back to the drawing board and spending quite a bit more time on solving the filtering issue with AJAX, I've got another patch ready.
Patch highlights:

  • Choosing a Relation Type will filter the Entity dropdown options.
  • The Relation Type dropdown will disable itself after the first Pick so that you cannot switch types which may forbid some or all of the currently Picked entities.
  • Clearing out the Picks will unlock the Relation Type dropdown so that another Type may be chosen.
  • If there is only one Relation Type, it will automatically be selected.
  • If there is only one Entity to choose from, it will be automatically selected (but not Picked).

Status: Needs review » Needs work

The last submitted patch, _relation-entity_collector_ajax_filter-1611752-9.patch, failed testing.

Uncle_Code_Monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new6.93 KB

Based on the testbot feedback, I believe I have fixed the warnings as well as modified the test to account for the ajax work disabling the relation type select field.

steveoliver’s picture

Status: Needs review » Needs work

Uncle Code Monkey++

Passing tests looks good. If everything else looks good, a few Drupal coding standards nitpicks:

You can use the Coder Review module to help spot them.

+++ b/relation_entity_collector/relation_entity_collector.module
@@ -127,14 +127,34 @@ function relation_entity_collector($form, &$form_state) {
+  if (isset($_SESSION['relation_entity_keys']) && count($_SESSION['relation_entity_keys'])<1) {

Spaces:

')<1)' should be ') < 1)'

+++ b/relation_entity_collector/relation_entity_collector.module
@@ -127,14 +127,34 @@ function relation_entity_collector($form, &$form_state) {
+    //user may have chosen a type, but not picked any entities yet

Space between // and User (capitalize User)

+++ b/relation_entity_collector/relation_entity_collector.module
@@ -127,14 +127,34 @@ function relation_entity_collector($form, &$form_state) {
+    //if there is only one choice to pick from and we haven't picked it yet, auto-pick it.

Along with space, maybe rewrite to fit in 80 char.

Maybe something like

// Auto-pick option if it is the only option.

+++ b/relation_entity_collector/relation_entity_collector.module
@@ -127,14 +127,34 @@ function relation_entity_collector($form, &$form_state) {
+  $relation_type_object = (!empty($relation_type)) ? relation_type_load($relation_type) : null;

I'd do:

$relation_type_object = !empty($relation_type) ? relation_type_load($relation_type) : NULL;
+++ b/relation_entity_collector/relation_entity_collector.module
@@ -127,14 +127,34 @@ function relation_entity_collector($form, &$form_state) {
+  $all_entity_cache = (isset($form_state['all_entity_cache'])) ? $form_state['all_entity_cache'] : array();

Just my preference, I guess, but I'd remove the wrapping parens from isset() check.

+++ b/relation_entity_collector/relation_entity_collector.module
@@ -127,14 +127,34 @@ function relation_entity_collector($form, &$form_state) {
+      //required so that subsequent AJAX calls re-filter the list correctly

Spacing, capitalization, and punctuation.

...etc.

Uncle_Code_Monkey’s picture

Status: Needs work » Needs review

Thanks for the coding standards tips and especially the module to help spot check. I'll admit that I have not read all of the documentation regarding coding standards and basically tried to follow the code as I read it. I prefer to encase all my boolean evaluations in a set of (), especially if it's in the form () ? :. But that is a personal preference, but I'd rather use the standard for patches. I'll modify the patch so it fits and resubmit later.

Uncle_Code_Monkey’s picture

Same patch as in #11, but this time with changes to better match the coding standards.

mikran’s picture

Status: Needs review » Needs work

I was about to commit this but final testing gave me a fatal error. This happened when I tried to select 3rd node for my arity 2 relation.

Fatal error:
Recoverable fatal error: Argument 2 passed to drupal_array_get_nested_value() must be of the type array, null given, called in /var/www/d7/modules/field/field.form.inc on line 394 and defined in drupal_array_get_nested_value() (line 6578 of /var/www/d7/includes/common.inc).

Error message that got displayed afterwards
Relation has too many end points (is_subnode_of max arity 2)

I didn't reroll the patch yet, this error occured with the version at is was when the last patch was posted.

EDIT: If you don't select entity but submit the form without the error message does not get displayed to user (until next page load).

Uncle_Code_Monkey’s picture

Status: Needs work » Needs review

@mikran What you described in comment #15 has been the case for a while now and this patch does not even try to address such an issue (it only handles filtering the possible selections, not modifying the behavior of trying to choose more than what your relation defines). If you want this issue also addressed and fixed, I highly recommend it be a separate issue and not hold up this particular one.

darrellduane’s picture

I attempted to apply the patch in #14 but it wouldn't apply to the dev version released on February 7th. I have manually applied it and will post a patch shortly.

mikran’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Fair enough but, by the original bug report it's in scope to also limit by the amount of endpoints in addition to their type. Also tests are something that we need to go with this

darrellduane’s picture

Here is the patch described in #17

mikran’s picture

Status: Needs work » Needs review
StatusFileSize
new7.12 KB

Another reroll

clemens.tolboom’s picture

Component: Entity_collector » API

I get the error mentioned in #3 and again in #15 too.

Doing some debugging it appear when defining selecting an endpoint of a directed relation.

Could it have someting to do with the logic of

function relation_entity_collector_validate(...) {
...
      $_SESSION += array('relation_entity_keys' => array());
      $next_index = count($_SESSION['relation_entity_keys']);
      // If validation succeeds we will add this in the submit handler.
      $form_state['pick'] = array(
        'r_index'       => $next_index,

I had the same entity twice in my session.

Refreshing the page give a lot of validation hints on the wrong start-point / end-point for by directional relation.

Choosing the correct start-point then end-point makes it work. So patch solves what it advertises. The error has some other cause.

Should that be another issue? Yes please. RTBC to me.

mikran’s picture

Component: API » Entity collector
Issue summary: View changes
mikran’s picture

This patch fixes multiple AJAX related issues with entity collector. Now when endpoint is picked all of the entity collector form elements are updated to ensure that any changes to them are actually updated to form. Also any validation errors are now properly displayed inside the block.

mikran’s picture

mikran’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.