[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorCustomFieldConfigOptionType 4 extends PhabricatorConfigOptionType { 5 6 public function readRequest( 7 PhabricatorConfigOption $option, 8 AphrontRequest $request) { 9 10 $e_value = null; 11 $errors = array(); 12 $storage_value = $request->getStr('value'); 13 14 $in_value = json_decode($storage_value, true); 15 if (!is_array($in_value)) { 16 $in_value = array(); 17 } 18 19 // When we submit from JS, we submit a list (since maps are not guaranteed 20 // to retain order). Convert it into a map for storage (since it's far more 21 // convenient for us elsewhere). 22 $storage_value = ipull($in_value, null, 'key'); 23 $display_value = $storage_value; 24 25 return array($e_value, $errors, $storage_value, $display_value); 26 } 27 28 public function renderControl( 29 PhabricatorConfigOption $option, 30 $display_value, 31 $e_value) { 32 33 $field_base_class = $option->getCustomData(); 34 35 $field_spec = $display_value; 36 if (!is_array($field_spec)) { 37 $field_spec = PhabricatorEnv::getEnvConfig($option->getKey()); 38 } 39 40 // Get all of the fields (including disabled fields) by querying for them 41 // with a faux spec where no fields are disabled. 42 $faux_spec = $field_spec; 43 foreach ($faux_spec as $key => $spec) { 44 unset($faux_spec[$key]['disabled']); 45 } 46 47 // TODO: We might need to build a real object here eventually. 48 $faux_object = null; 49 50 $fields = PhabricatorCustomField::buildFieldList( 51 $field_base_class, 52 $faux_spec, 53 $faux_object); 54 55 $list_id = celerity_generate_unique_node_id(); 56 $input_id = celerity_generate_unique_node_id(); 57 58 $list = id(new PHUIObjectItemListView()) 59 ->setFlush(true) 60 ->setID($list_id); 61 foreach ($fields as $key => $field) { 62 $item = id(new PHUIObjectItemView()) 63 ->addSigil('field-spec') 64 ->setMetadata(array('fieldKey' => $key)) 65 ->setGrippable(true) 66 ->addAttribute($field->getFieldDescription()) 67 ->setHeader($field->getFieldName()); 68 69 $is_disabled = !empty($field_spec[$key]['disabled']); 70 71 $disabled_item = clone $item; 72 $enabled_item = clone $item; 73 74 if ($is_disabled) { 75 $list->addItem($disabled_item); 76 } else { 77 $list->addItem($enabled_item); 78 } 79 80 $disabled_item->addIcon('none', pht('Disabled')); 81 $disabled_item->setDisabled(true); 82 $disabled_item->addAction( 83 id(new PHUIListItemView()) 84 ->setHref('#') 85 ->addSigil('field-spec-toggle') 86 ->setIcon('fa-plus')); 87 88 $enabled_item->setBarColor('green'); 89 90 if (!$field->canDisableField()) { 91 $enabled_item->addAction( 92 id(new PHUIListItemView()) 93 ->setIcon('fa-lock grey')); 94 $enabled_item->addIcon('none', pht('Permanent Field')); 95 } else { 96 $enabled_item->addAction( 97 id(new PHUIListItemView()) 98 ->setHref('#') 99 ->addSigil('field-spec-toggle') 100 ->setIcon('fa-times')); 101 } 102 103 $fields[$key] = array( 104 'disabled' => $is_disabled, 105 'disabledMarkup' => $disabled_item->render(), 106 'enabledMarkup' => $enabled_item->render(), 107 ); 108 } 109 110 $input = phutil_tag( 111 'input', 112 array( 113 'id' => $input_id, 114 'type' => 'hidden', 115 'name' => 'value', 116 'value' => json_encode($display_value), 117 )); 118 119 Javelin::initBehavior( 120 'config-reorder-fields', 121 array( 122 'listID' => $list_id, 123 'inputID' => $input_id, 124 'fields' => $fields, 125 )); 126 127 return id(new AphrontFormMarkupControl()) 128 ->setLabel(pht('Value')) 129 ->setError($e_value) 130 ->setValue( 131 array( 132 $list, 133 $input, 134 )); 135 } 136 137 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |