You are here

function block_patterns_callbacks in Patterns 7

File

patterns_components/components/block.inc, line 198

Code

function block_patterns_callbacks($action, $tag, &$data) {
  if ($tag == 'block') {
    $keys = array(
      'module',
      'delta',
      'theme',
      'weight',
      'region',
      'status',
    );
    $diff = array_diff($data, $keys);

    // TODO: document, make this clearer.
    // Adding a new block: unknown id (or, module-delta) and a known info field.
    if ($action === PATTERNS_CREATE && !($data['module'] && $data['delta']) && $data['info']) {

      // $tag should be create
      $result = array(
        'block_add_block_form',
        // This will call block_admin_configure($form, $form_state, 'block', NULL);
        'block_admin_display_form',
      );
    }
    elseif ($action === PATTERNS_DELETE) {

      // Deleting a custom block.
      $result = array(
        'block_custom_block_delete',
      );
    }
    elseif (empty($diff)) {

      // Only editing the position for one theme.
      $result = array(
        'block_admin_display_form',
      );

      // TODO: check _block_patterns_display_keys()
    }
    elseif ($action === PATTERNS_MODIFY) {

      // Editing a block
      $result = array(
        'block_admin_configure',
        'block_admin_display_form',
      );
    }
    else {

      // TODO
    }
  }
  return patterns_results(PATTERNS_SUCCESS, t('Execution successful'), $result);
}