From aea655eb9c2c432f5e657ac9b09f5b128fa5bdef Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 11 May 2016 13:42:07 +0530 Subject: [PATCH] Add formatDisplayField() and columnType() methods to CrudViewHelper. This allows easier overriding and better control over generated output. --- src/View/Helper/CrudViewHelper.php | 38 +++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index 542cae89..de7bdc54 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -122,13 +122,7 @@ public function introspect($field, $value, array $options = []) return $output['output']; } - - $schema = $this->schema(); - if (method_exists($schema, 'baseColumnType')) { - $type = $schema->baseColumnType($field); - } else { - $type = $schema->columnType($field); - } + $type = $this->columnType($field); if ($type === 'boolean') { return $this->formatBoolean($field, $value, $options); @@ -145,12 +139,28 @@ public function introspect($field, $value, array $options = []) $value = $this->formatString($field, $value); if ($field === $this->getViewVar('displayField')) { - $value = $this->createViewLink($value, ['escape' => false]); + return $this->formatdisplayField($value, $options); } return $value; } + /** + * Get column type from schema. + * + * @param string $field Field to get column type for + * @return string + */ + public function columnType($field) + { + $schema = $this->schema(); + if (method_exists($schema, 'baseColumnType')) { + return $schema->baseColumnType($field); + } + + return $schema->columnType($field); + } + /** * Format a boolean value for display * @@ -211,6 +221,18 @@ public function formatString($field, $value) return h(Text::truncate($value, 200)); } + /** + * Format display field value. + * + * @param string $value Display field value. + * @param array $options Field options. + * @return string + */ + public function formatDisplayField($value, array $options) + { + return $this->createViewLink($value, ['escape' => false]); + } + /** * Returns a formatted relation output for a given field *