You are here

function coder_upgrade_upgrade_hook_form_alter_alter in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_upgrade/conversions/function.inc \coder_upgrade_upgrade_hook_form_alter_alter()

Implements hook_upgrade_hook_form_alter().

File

coder_upgrade/conversions/function.inc, line 316
Provides conversion routines applied to functions (or hooks).

Code

function coder_upgrade_upgrade_hook_form_alter_alter(&$node, &$reader) {

  // Changes: node_form
  $editor = PGPEditor::getInstance();

  /*
   * What if:
   * - the code uses a name other than $form?
   * - the conditions are in different order or on multiple lines?
   */

  // Conditions to test for a node edit form.
  $node_form_conditional = '/isset\\(\\$form\\[\'type\'\\]\\)\\s*&&\\s*' . 'isset\\(\\$form\\[\'#node\'\\]\\)\\s*&&\\s*' . '\\$form\\[\'type\'\\]\\[\'#value\'\\]\\s*.\\s*\'_node_form\' == \\$form_id/';

  // Loop on the body statements looking for conditional statment.
  $current =& $node->data->body
    ->first();
  while ($current->next != NULL) {
    $statement =& $current->data;
    if ($statement instanceof PGPConditional) {

      // Get the list of conditons.
      $conditions = $statement->conditions;

      // Check if conditions match node form check.
      if ($conditions instanceof PGPList) {
        $conditions = $conditions
          ->toString();
        if (preg_match($node_form_conditional, $conditions)) {

          // Replace verbose node edit form condtional.
          $conditions = preg_replace($node_form_conditional, '!empty($form[\'#node_edit_form\'])', $conditions);
          $statement->conditions = $editor
            ->expressionToStatement($conditions);
        }
      }
    }

    // Move to next node.
    $current =& $current->next;
  }
}