00001 <?php
00002
00003
00004
00005
00006 define('CONTEXT_NODE_VIEW', 0);
00007
00008
00009
00010
00011 define('CONTEXT_NODE_FORM', 1);
00012
00013
00014
00015
00016 define('CONTEXT_NODE_FORM_ONLY', 2);
00017
00018
00019
00020
00021 class context_condition_node extends context_condition {
00022 function condition_values() {
00023 $values = array();
00024 foreach (node_type_get_types() as $type) {
00025 $values[$type->type] = check_plain($type->name);
00026 }
00027 return $values;
00028 }
00029
00030 function options_form($context) {
00031 $defaults = $this->fetch_from_context($context, 'options');
00032 return array(
00033 'node_form' => array(
00034 '#title' => t('Set on node form'),
00035 '#type' => 'select',
00036 '#options' => array(
00037 CONTEXT_NODE_VIEW => t('No'),
00038 CONTEXT_NODE_FORM => t('Yes'),
00039 CONTEXT_NODE_FORM_ONLY => t('Only on node form')
00040 ),
00041 '#description' => t('Set this context on node forms'),
00042 '#default_value' => isset($defaults['node_form']) ? $defaults['node_form'] : TRUE,
00043 ),
00044 );
00045 }
00046
00047 function execute($node, $op) {
00048 foreach ($this->get_contexts($node->type) as $context) {
00049
00050 $options = $this->fetch_from_context($context, 'options');
00051 if ($op === 'form') {
00052 $options = $this->fetch_from_context($context, 'options');
00053 if (!empty($options['node_form']) && in_array($options['node_form'], array(CONTEXT_NODE_FORM, CONTEXT_NODE_FORM_ONLY))) {
00054 $this->condition_met($context, $node->type);
00055 }
00056 }
00057 elseif (empty($options['node_form']) || $options['node_form'] != CONTEXT_NODE_FORM_ONLY) {
00058 $this->condition_met($context, $node->type);
00059 }
00060 }
00061 }
00062 }