3

I have 2 content types business, locations, programs and services.

At program level we select all the services associated with that program.

At business level we select the programs the business is associated with.

At the location level based on the programs selected we give the option to sub select the services.

Now the services entity reference is displayed via Entity Reference View Widget. All I want to do is alter or unset certain options based on the choices made at the business level in terms of program selection.

I tried working at the views level to pass it as an argument but was unsuccessful. Then tried the node form alter but the unset option still shows up but without the checkbox. enter image description here

Tried to alter it using hook_field_widget_form_alter as well but was not successful.

It looks like it implements a preprocess function entityreference_view_widget_preprocess_widget but I am not able to override it.

Looking for pointers if anyone has come across similar problem.

1

Ending up using hook_views_pre_render(&$view). So I did something like this

function contractor_programs_views_pre_render(&$view) {
  if ($view->name == 'location_services' && $view->current_display == 'entityreference_view_widget_1') {
    // added my logic to get the service options
    if (!empty($services_options)) {
        $services_options = array_keys($services_options);
        if (!empty($view->result)) {
          foreach($view->result as $key => $value) {
            if (!in_array($value->nid, $services_options)) {
              unset($view->result[$key]);
            }
          }
        }
      }
  }
}

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.