1

I have a field called 'Remarks' on an ECK entity (not a node) and Role A is allowed to leave remarks but I don't want them to edit previous remarks, I just want to give them the option to add one. Note: they are not the author or owner of the entity. Right now, I use an Edit Page Variant for this entity that they have access to and where this form for 'field_remarks' appears. The problem is that the previously added remarks are still showing up and therefore now they can still edit someone else's remarks.

potential solution 1

I would probably be possible to hide the fields that already contain values with jQuery but that is not really the Drupal way, I believe.

potential solution 2

Could it possibly be done with a Rules component that adds the value (text) to this field programmatically? And if so, how and where to show a text field that would accomplish that?

2 Answers 2

1

You can programmatically disable them in module like this:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
   if($form_id == 'eck__entity__form_edit_ENTITY_NAME_BUNDLE_NAME') {
     $lang = $form['field_name']['#language'];
     foreach ($form['field_name'][$lang] as $key => $value) {
       if (is_numeric($key) && !empty($value['value']['#default_value'])) {
         $form['field_name'][$lang][$key]['value']['#disabled'] = TRUE;
       }
     }
   }
}

Result

enter image description here

1
  • Thank you so much No Sssweat ! I'll try that and provide feedback.
    – BassPlaya
    Sep 22, 2020 at 21:15
0

Answer Using jQuery:

Like so we can check which fields have contain a something (a value).

$( "table#field-remarks-values > tbody > tr textarea" )
.not( "textarea:empty" )
.parentsUntil("tbody")
.addClass("hidden");

Maybe a better way is to remove them entirely:

$( "table#field-remarks-values > tbody > tr textarea" )
.not( "textarea:empty" )
.parentsUntil("tbody")
.remove();

This may be more difficult to bring them up again if at all.

It's a solution that works for now but not the best solution in my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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