'includeCustom' => FALSE,
]);
$result = new Result();
- $getFields->_run($result);
+ // Pass TRUE for the private $isInternal param
+ $getFields->_run($result, TRUE);
$this->_entityFields = (array) $result->indexBy('name');
}
return $this->_entityFields;
else {
$values = $this->getRecords();
}
- $this->formatResults($values);
+ // $isInternal param is not part of function signature (to be compatible with parent class)
+ $isInternal = func_get_args()[1] ?? FALSE;
+ $this->formatResults($values, $isInternal);
$this->queryArray($values, $result);
}
* Instead just override $this->fields and this function will respect that.
*
* @param array $values
+ * @param bool $isInternal
*/
- protected function formatResults(&$values) {
+ protected function formatResults(&$values, $isInternal) {
$fieldDefaults = array_column($this->fields(), 'default_value', 'name') +
array_fill_keys(array_column($this->fields(), 'name'), NULL);
// Enforce field permissions
}
}
}
+ // Unless this is an internal getFields call, filter out @internal properties
+ $internalProps = $isInternal ? [] : array_filter(array_column($this->fields(), '@internal', 'name'));
foreach ($values as &$field) {
$defaults = array_intersect_key([
'title' => empty($field['name']) ? NULL : ucwords(str_replace('_', ' ', $field['name'])),
if (isset($defaults['options'])) {
$field['options'] = $this->formatOptionList($field['options']);
}
+ $field = array_diff_key($field, $internalProps);
}
}
[
'name' => 'output_formatters',
'data_type' => 'Array',
+ '@internal' => TRUE,
],
];
}
/**
* @var callable[]
*/
- public $outputFormatters = [];
+ public $outputFormatters;
/**
* Aliases for the valid data types
return $this;
}
- /**
- * @return callable[]
- */
- public function getOutputFormatters() {
- return $this->outputFormatters;
- }
-
/**
* @param callable[] $outputFormatters
* @return $this
* @return $this
*/
public function addOutputFormatter($outputFormatter) {
+ if (!$this->outputFormatters) {
+ $this->outputFormatters = [];
+ }
$this->outputFormatters[] = $outputFormatter;
return $this;
}
- /**
- * @return bool
- */
- public function getreadonly() {
- return $this->readonly;
- }
-
/**
* @param bool $readonly
* @return $this
*/
- public function setreadonly($readonly) {
+ public function setReadonly($readonly) {
$this->readonly = (bool) $readonly;
return $this;
}
- /**
- * @return string|NULL
- */
- public function getHelpPre() {
- return $this->helpPre;
- }
-
/**
* @param string|NULL $helpPre
*/
$this->helpPre = is_string($helpPre) && strlen($helpPre) ? $helpPre : NULL;
}
- /**
- * @return string|NULL
- */
- public function getHelpPost() {
- return $this->helpPost;
- }
-
/**
* @param string|NULL $helpPost
*/
/**
* @param string $customFieldColumnName
- *
- * @return CustomFieldSpec
+ * @return $this
*/
public function setTableName($customFieldColumnName) {
$this->tableName = $customFieldColumnName;
return $this;
}
- /**
- * @return callable
- */
- public function getOptionsCallback() {
- return $this->optionsCallback;
- }
-
/**
* @return string
*/
if ($action !== 'create') {
$idField = new FieldSpec('id', $spec->getEntity(), 'Integer');
$idField->setTitle(ts('Custom Value ID'));
- $idField->setreadonly(TRUE);
+ $idField->setReadonly(TRUE);
$spec->addFieldSpec($idField);
}
$entityField = new FieldSpec('entity_id', $spec->getEntity(), 'Integer');
$entityField->setTitle(ts('Entity ID'));
$entityField->setRequired($action === 'create');
$entityField->setFkEntity('Contact');
- $entityField->setreadonly(TRUE);
+ $entityField->setReadonly(TRUE);
$spec->addFieldSpec($entityField);
}
if (self::customFieldHasOptions($data)) {
$field->setOptionsCallback([__CLASS__, 'getOptions']);
}
- $field->setreadonly($data['is_view']);
+ $field->setReadonly($data['is_view']);
}
else {
$name = $data['name'] ?? NULL;
if (!empty($data['pseudoconstant'])) {
$field->setOptionsCallback([__CLASS__, 'getOptions']);
}
- $field->setreadonly(!empty($data['readonly']));
+ $field->setReadonly(!empty($data['readonly']));
}
$field->setSerialize($data['serialize'] ?? NULL);
$field->setDefaultValue($data['default'] ?? NULL);
$this->assertCount(1, $fields);
}
+ public function testInternalPropsAreHidden() {
+ // Public getFields should not contain @internal props
+ $fields = Contact::getFields(FALSE)
+ ->execute()
+ ->getArrayCopy();
+ foreach ($fields as $field) {
+ $this->assertArrayNotHasKey('output_formatters', $field);
+ }
+ // Internal entityFields should contain @internal props
+ $fields = Contact::get(FALSE)
+ ->entityFields();
+ foreach ($fields as $field) {
+ $this->assertArrayHasKey('output_formatters', $field);
+ }
+ }
+
}