Skip to content

Commit

Permalink
Add formatDisplayField() and columnType() methods to CrudViewHelper.
Browse files Browse the repository at this point in the history
This allows easier overriding and better control over generated output.
  • Loading branch information
ADmad committed May 11, 2016
1 parent 0dd8e28 commit aea655e
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit aea655e

Please sign in to comment.