protected function getOptions() { $options = array(); foreach ($this->policies as $policy) { if ($policy->getPHID() == PhabricatorPolicies::POLICY_PUBLIC && $this->capability != PhabricatorPolicyCapability::CAN_VIEW) { // Never expose "Public" for anything except "Can View". continue; } $type_name = PhabricatorPolicyType::getPolicyTypeName($policy->getType()); $options[$type_name][$policy->getPHID()] = $policy->getFullName(); } return $options; }
public function getSortKey() { return sprintf('%02d%s', PhabricatorPolicyType::getPolicyTypeOrder($this->getType()), $this->getSortName()); }
protected function renderInput() { if (!$this->object) { throw new PhutilInvalidStateException('setPolicyObject'); } if (!$this->capability) { throw new PhutilInvalidStateException('setCapability'); } $policy = $this->object->getPolicy($this->capability); if (!$policy) { // TODO: Make this configurable. $policy = PhabricatorPolicies::POLICY_USER; } if (!$this->getValue()) { $this->setValue($policy); } $control_id = celerity_generate_unique_node_id(); $input_id = celerity_generate_unique_node_id(); $caret = phutil_tag('span', array('class' => 'caret')); $input = phutil_tag('input', array('type' => 'hidden', 'id' => $input_id, 'name' => $this->getName(), 'value' => $this->getValue())); $options = $this->getOptions(); $order = array(); $labels = array(); foreach ($options as $key => $values) { $order[$key] = array_keys($values); $labels[$key] = PhabricatorPolicyType::getPolicyTypeName($key); } $flat_options = array_mergev($options); $icons = array(); foreach (igroup($flat_options, 'icon') as $icon => $ignored) { $icons[$icon] = id(new PHUIIconView())->setIconFont($icon); } if ($this->templatePHIDType) { $context_path = 'template/' . $this->templatePHIDType . '/'; } else { $object_phid = $this->object->getPHID(); if ($object_phid) { $context_path = 'object/' . $object_phid . '/'; } else { $object_type = phid_get_type($this->object->generatePHID()); $context_path = 'type/' . $object_type . '/'; } } Javelin::initBehavior('policy-control', array('controlID' => $control_id, 'inputID' => $input_id, 'options' => $flat_options, 'groups' => array_keys($options), 'order' => $order, 'icons' => $icons, 'labels' => $labels, 'value' => $this->getValue(), 'capability' => $this->capability, 'editURI' => '/policy/edit/' . $context_path, 'customPlaceholder' => $this->getCustomPolicyPlaceholder(), 'disabled' => $this->getDisabled())); $selected = idx($flat_options, $this->getValue(), array()); $selected_icon = idx($selected, 'icon'); $selected_name = idx($selected, 'name'); $spaces_control = $this->buildSpacesControl(); return phutil_tag('div', array(), array($spaces_control, javelin_tag('a', array('class' => 'grey button dropdown has-icon policy-control', 'href' => '#', 'mustcapture' => true, 'sigil' => 'policy-control', 'id' => $control_id), array($caret, javelin_tag('span', array('sigil' => 'policy-label', 'class' => 'phui-button-text'), array(idx($icons, $selected_icon), $selected_name)))), $input)); return AphrontFormSelectControl::renderSelectTag($this->getValue(), $this->getOptions(), array('name' => $this->getName(), 'disabled' => $this->getDisabled() ? 'disabled' : null, 'id' => $this->getID())); }