Hello.
I found a nasty bug. The bean block has two fields - label and title by default.
Field label is mandatory and title field is optional.

In Hook function bean_entity_info ()

indicated that as the label to use the field title

       'entity keys' => array (
         'id' => 'bid',
         'bundle' => 'type',
         'label' => 'title',
         'name' => 'delta',
         'revision' => 'vid',
         'default revision' => 'default_revision',
       )

I use modules and entityreference & references_dialog to attach the bean block to the node. Because the title is not a mandatory field, you may have the following image:
http://i.imgur.com/weXy407.png

And should be so:
http://i.imgur.com/vqjwYC6.png

This error is then that entity api tries to put as a title of bean block field "title", but user can leave this field blank. If this situation occured - user is confused.

I see two ways to resolve the problem:

1. Make mandatory title field.
2. Set the 'label' => 'label' in 'entity keys'

Which variant is better for you? I will write patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

indytechcook’s picture

This is related to #1911262: EntityReference integration should display the label field, not title

Since entity reference uses the entity_label() function and bean uses the entity_class_label callback, the label() then the defaultLabel() methods are used on the class. The "correct" way would be to override the defaultLabel() method and show the label field if the title field is empty.

indytechcook’s picture

More information

The purpose of the title field is the same as the "Block description" or "The title of the block as shown to the user."
THe purpose of the label field is the same as the "Block title" or "Block description"

One of the most difficult aspects of this module is keeping it's structure similar to the block module. I do find this confuses people at times.

The defaultLabel() method should follow this logic.

  1. First check if there is a label. If there is then use it.
  2. If there is no label then use the title.

Corresponding issue in entity reference module: #1911266: autocomplete field should use field selected for sorting

indytechcook’s picture

There have been several issues around the label/title usage.

#1836798: Block Label used rather than Title on block/delta and block/delta/view
#1845974: Block Admin label is correct

We need the following tests with this issue:

  • Title is correct on bean view page with an empty title.
  • Title is correct on bean view page with a title filled out.
  • Title is correct on block list page with an empty title.
  • Title is correct on block list page with a title filled out.
indytechcook’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
1.02 KB

Here is a patch without the tests. Setting to needs review to run current tests but I'd still like to see other tests added before this gets committed.

DamienMcKenna’s picture

Just as a general comment, you shouldn't include changes to the CHANGELOG.txt file in the patch, that should be manually added when you're committing the changes.

The patch in #4 works for me.

eugene.ilyin’s picture

>The patch in #4 works for me.
ok, this patch will be applied? my help is not need?

indytechcook’s picture

Status: Needs review » Fixed

Posted to wrong issue.

indytechcook’s picture

saltednut’s picture

Status: Fixed » Active

Should be active?

  1. Tagged as Needs tests
  2. The getTranslation method will call entity_get_all_property_info($this->entityType); -- for Beans, this returns empty. I have seen errors as a result:
    Notice: Undefined index: title in Entity->getTranslation() (line 256 of /entity/includes/entity.inc).
saltednut’s picture

I've tested this with Entity 1.0 and the latest bean dev.

I've also tested this using latest dev and entity 7.x-1.x dev.

Did anyone else test this patch before it was committed?

The defaultLabel() method should follow this logic.

First check if there is a label. If there is then use it.
If there is no label then use the title.

I don't think this will give the result we want.

When a Bean is rendered (ex: in a region), using this logic, you'll show the label - when you really want to see the title.

Notice: Undefined index: title in Entity->getTranslation() (line 256 of /entity/includes/entity.inc).

I'm attaching two patches, both without the translation. One uses the label as the defaultLabel, one uses title as defaultLabel.

Bean Admin UI Bean
1916938-admin-screen.png
Bean on the Listings Page
1916938-block-list.png
Bean Using Latest Dev
1916938-pre-patch.png
Removed getTranslation (patch a)
1916938-patch-a.png
Removed getTranslation and swapped label with title (patch b)
1916938-patch-b.png

Note: both patches also fix some erroneous quote styling.

DamienMcKenna’s picture

Patch b from #10 resolves the problem of the block's title being incorrect on display, but I've not yet tested it with EntityReference.

saltednut’s picture

Committed b per #1935770: Bean label is used as block subject

I believe this issue is resolved now. Tested latest dev with an entity reference and I am seeing Bean titles in the EntityReference field.
Screen Shot 2013-03-14 at 2.41.49 PM.png

saltednut’s picture

Status: Needs review » Fixed

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