Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/customfield/field/PhabricatorCustomField.php
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | public static function getObjectFields( | ||||
| try { | try { | ||||
| $field_list = $attachment->getCustomFieldList($role); | $field_list = $attachment->getCustomFieldList($role); | ||||
| } catch (PhabricatorCustomFieldNotAttachedException $ex) { | } catch (PhabricatorCustomFieldNotAttachedException $ex) { | ||||
| $base_class = $object->getCustomFieldBaseClass(); | $base_class = $object->getCustomFieldBaseClass(); | ||||
| $spec = $object->getCustomFieldSpecificationForRole($role); | $spec = $object->getCustomFieldSpecificationForRole($role); | ||||
| if (!is_array($spec)) { | if (!is_array($spec)) { | ||||
| $obj_class = get_class($object); | |||||
| throw new Exception( | throw new Exception( | ||||
| "Expected an array from getCustomFieldSpecificationForRole() for ". | pht( | ||||
| "object of class '{$obj_class}'."); | "Expected an array from %s for object of class '%s'.", | ||||
| 'getCustomFieldSpecificationForRole()', | |||||
| get_class($object))); | |||||
| } | } | ||||
| $fields = self::buildFieldList( | $fields = self::buildFieldList( | ||||
| $base_class, | $base_class, | ||||
| $spec, | $spec, | ||||
| $object); | $object); | ||||
| foreach ($fields as $key => $field) { | foreach ($fields as $key => $field) { | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public static function buildFieldList( | ||||
| $fields = array(); | $fields = array(); | ||||
| $from_map = array(); | $from_map = array(); | ||||
| foreach ($field_objects as $field_object) { | foreach ($field_objects as $field_object) { | ||||
| $current_class = get_class($field_object); | $current_class = get_class($field_object); | ||||
| foreach ($field_object->createFields($object) as $field) { | foreach ($field_object->createFields($object) as $field) { | ||||
| $key = $field->getFieldKey(); | $key = $field->getFieldKey(); | ||||
| if (isset($fields[$key])) { | if (isset($fields[$key])) { | ||||
| $original_class = $from_map[$key]; | |||||
| throw new Exception( | throw new Exception( | ||||
| "Both '{$original_class}' and '{$current_class}' define a custom ". | pht( | ||||
| "field with field key '{$key}'. Field keys must be unique."); | "Both '%s' and '%s' define a custom field with ". | ||||
| "field key '%s'. Field keys must be unique.", | |||||
| $from_map[$key], | |||||
| $current_class, | |||||
| $key)); | |||||
| } | } | ||||
| $from_map[$key] = $current_class; | $from_map[$key] = $current_class; | ||||
| $fields[$key] = $field; | $fields[$key] = $field; | ||||
| } | } | ||||
| } | } | ||||
| foreach ($fields as $key => $field) { | foreach ($fields as $key => $field) { | ||||
| if (!$field->isFieldEnabled()) { | if (!$field->isFieldEnabled()) { | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | switch ($role) { | ||||
| return $this->shouldAppearInConduitDictionary(); | return $this->shouldAppearInConduitDictionary(); | ||||
| case self::ROLE_TRANSACTIONMAIL: | case self::ROLE_TRANSACTIONMAIL: | ||||
| return $this->shouldAppearInTransactionMail(); | return $this->shouldAppearInTransactionMail(); | ||||
| case self::ROLE_HERALD: | case self::ROLE_HERALD: | ||||
| return $this->shouldAppearInHerald(); | return $this->shouldAppearInHerald(); | ||||
| case self::ROLE_DEFAULT: | case self::ROLE_DEFAULT: | ||||
| return true; | return true; | ||||
| default: | default: | ||||
| throw new Exception("Unknown field role '{$role}'!"); | throw new Exception(pht("Unknown field role '%s'!", $role)); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Allow administrators to disable this field. Most fields should allow this, | * Allow administrators to disable this field. Most fields should allow this, | ||||
| * but some are fundamental to the behavior of the application and can be | * but some are fundamental to the behavior of the application and can be | ||||
| * locked down to avoid chaos, disorder, and the decline of civilization. | * locked down to avoid chaos, disorder, and the decline of civilization. | ||||
| ▲ Show 20 Lines • Show All 1,057 Lines • Show Last 20 Lines | |||||