Have hundreds of items in one multivalued field?

Sounds like a bad design? When the first time I found out this, I thought that we should have avoided it in design. But, that is not what we are talking today. After we I figured out a way to fix the performance, it seems quite a powerful way to deal with the business logic.

How to accommodate the request that a node holds thousands of multiple value items in one field? When it comes to editor experience, we have something to share. Multiple values field for a field-collection-item is a usual setup for a content type. When there are only couple dozens of values, everything is good. The default field-collection embed widget with a multivalue field is working well.

As the number of items goes up, the editing page become heavier. In our case, we have a field collection contains five subfields. There is one entity reference field pointing to nodes, two text fields, one taxonomy entity reference field and a number field. Some nodes have over 300 such field collection items. The editing pages for those nodes are like taking forever to load. Updating the node getting more and more difficult.

for such a node, the edit form has thousands of form elements. It is like loading an adult elephant with a small pickup truck. Anything can slow down the page. That can be from web server performance to the network bandwidth and our local computer browser capability. So, we need to find a valid way to handle it. We want the multiple value field to be truly unlimited. Make it capable of holding thousands of field-collection-items value in a single node.

After doing some research, we come with a pretty good solution. Here is what we had done to deal with it.

We use Embeded Views Field to build a block for the field collection items. We paginate it and break down 300 items into 12 pages. Then, we insert the views block into the node editing page. Not loading all the elements into the node editing form, it speeds up the page loading immediately. Display the field collection items in views block is not enough, we need to edit them. I had tried to use the VBO to handle editing and deleting. It did not work. Then we built some custom ajax functions for editing and deleting. We use the ctools modal window as front end interface to edit, delete and add new items. That works well. With modal window and Ajax, we can keep the main node edit page untouched. There is no need to refresh the page every time they change the field-collection-items. Thanks to the pagination of the views block. We now can add as many items as we want into the field collection multivalue field. We added views sorting function to the embedded views field.

Sounds pretty robust, but wait, there is something missing. We quickly running into problem soon we implement it. What about the form to create a new node? On the new node page, the embedded views field block is not working. A new node does not have its node id. We fixed it by using the default widget. It is just for the new node page. We used the following function to switch the field widget.

function MODULENAME_field_widget_properties_alter(&$widget, $context) {
  if ($context['entity_type'] == 'node') {
    if (!isset($context['entity']->nid)) {
      if ($context['field']['field_name'] == 'FIELD_MACHINE_NAME') {
        if ($widget['type'] == 'field_collection_hidden') {
          $widget['type'] = 'field_collection_embed';
        }
      }
    }
  }
}

Comments

Are you sure there was not a better logic?

Thousands of embed things sounds scary... are you sure there is not a better way to handle the logic? Once you figure it out, "just" build and run the migration path :) what about saving everything in a json it loads fast?

Thanks for sharing your

Thanks for sharing your solution. As you mention in your post, it's also necessary to edit the field items, not just display them. Could you share the "custom ajax functions for editing and deleting" that you built to implement edit / delete capabilities in the embedded view?

We used the Editable Fields

Try the Editable Fields module.

Интересная фотоподборка

Привет всем участникам! Нашел познавательную фотосессию на этом сайте: http://coolrobo.ru : http://coolrobo.ru/foto-prikoly-interesnoe/5947-simpatichnye-doma-iz-plastikovyh-butylok.html <b> Симпатичные дома из пластиковых бутылок </b> <a href=http://coolrobo.ru/foto-prikoly-interesnoe/4535-strany-bez-podohodnogo-naloga.html> Страны без подоходного налога </a> http://coolrobo.ru/foto-prikoly-interesnoe/1671-miss-mira-2014-predstavit-anastasiya-kostenko.html

сериалы 2017 смотреть хорошем качестве русские криминальные

Привет всем участникам форума! класный у вас сайт! Нашел прикольную базу кино: <b> храброе сердце мультфильм в хорошем качестве онлайн </b> <a href=http://kinokub.net/>http://kinokub.net/</a> Тут: <a href=http://kinokub.net/fentezi/>самые лучшие фильмы фэнтези смотреть онлайн</a> фэнтези смотреть бесплатно в хорошем качестве список 2017 Здесь: Онлайн лучшие драмы http://kinokub.net/drama/ список 2018 Здесь: Документальные фильмы онлайн смотреть http://kinokub.net/dokumentalnyy/ список 2017 Здесь: http://kinokub.net/melodrama/4263-druzhba-i-nikakogo-seksa-what-if-2013.html <b> Смотреть Дружба и никакого секса? / What If (2013) онлайн бесплатно </b> Здесь: http://kinokub.net/raznoe/5831-rozhdestvenskiy-zherebenok-the-christmas-colt-2013.html

Best Spa body rub in New Yourk

In spa salon grooming massage masseurs can do the sexiest Aromatherapy. Our women enough qualified in order to at the end session body to body massage you felt yourself easy good and were always ready to indescribable sexual feats. The spa salon erotic invites visit one of the options massage, is what we do. The beautiful masseuses our the spa will give you an unforgettable experience. The spa is a place of rest and relaxation. We in N.Y.C. are ready to provide beautiful placement with convenient style. These placement promote be you you are staying with us incognito. Attractive massage therapists will make you Intimate massage and relaxing massage, you can select several varieties massage on your solution. Success organization nuru massage composed, in order that, in 1st you received from him satisfaction. Warm touching chic masters of massage there will be a flow on your body, immersing in abyss boundless seas pleasure. In the slow slip, covering your body kisses, prelestress enshroud the warmth of one's body. You personally be able to be surprised by that, which sea enjoyment you can know fromSoapy massage in Empire State Our showroom works in Downtown. Girls Trinity <a href=https://japanese.massage-manhattan-club.com>japanese massage cabinet</a>

Add new comment

Target Image