How can I make revision log message required based on revision checkbox by node_form_alter? My goal is to make the "revision log message" required if "Create new revision" is checked on create/edit node.

I do able to add the visible and required mark based on the "create new revision" field.

function hook_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  $form['revision_information']['log']['#states'] = [
    'required' =&gt; [
      ':input[name="revision"]' =&gt; ['checked' =&gt; TRUE],
    ],
    'visible'  =&gt; [
      ':input[name="revision"]' =&gt; ['checked' =&gt; TRUE],
    ],
  ];
}


I also able to make the "revision log message" as required.

function hook_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  $form['revision_information']['log']['#required'] = [
    'required' =&gt; [
      ':input[name="revision"]' =&gt; ['checked' =&gt; TRUE],
    ],
  ];
}


But I don't know how to make the field required based on the "create new revision" checkbox.

PS: I want to make this simple and don't want to use the "Enforce revision log message" module.

// update 1: I found it require a custom hook validate and Im searching for it
I found an answer after hours of searching. Basically, I just need to add a custom hook validation for revision log. See below for my code.

function MYMODULENAME_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    // change revision log status based on revision checkbox
    $form['revision_information']['log']['#states'] = array(
        'required' =&gt; array(
          ':input[name="revision"]' =&gt; array('checked' =&gt; TRUE),
        ),
        'visible' =&gt; array(
          ':input[name="revision"]' =&gt; array('checked' =&gt; TRUE),
        ),
    );
}
function MYMODULENAME_node_validate($node, $form, &amp;$form_state) {
    // add revision log validation
    if (empty($form_state['values']['log']) &amp;&amp; ($form_state['values']['revision'])) {
        form_set_error('log', 'Revision log message cannot be empty!');
    }
}


I hope this helps someone who needs revision log message required.