Scenario
I want to include the created property of my entity, in the Inline entity form - Multiple values widget. But I don't want to display the timestamp, I want to show a more readable date format, by using the format_date() function (or any other function for that matter).
Proposal
Add an option in the table fields (the array returned from the tableFields() controller function), that will allow a function to alter the output.
So a field definition could look like the following:
$fields['created'] = array(
'type' => 'property',
'label' => t('Created'),
'weight' => 2,
'process' => 'format_date' // The new output altering function
);
I don't know if process is the right word for this option, but it's what I've been using in my own altered IEF version.
Solution
Inject the function in the theme_inline_entity_form_entity_table(), before the actual data is added to the $cells array.
Comments
Comment #1
birk commentedInstead of putting the call right before the data is added to the
$cellsarray, I've added the call in the property condition.This way the process option is only used on properties and not on fields, where changes like this should be done in the formatter.
Comment #2
cyborg_572 commentedI found this very useful, but needed to be able to pass arguments to the formatter, so I extended the patch a little to support an array of arguments.
Comment #3
michfuer commented+1 for usefulness.
I couldn't apply the patch in #2 (it's stale). Here's an updated one.
Comment #4
cyborg_572 commentedThe patch in #3 drops the ability to use an integer 1 to pass the property value as anything other than the first argument to the formatter (kind of like how hook_menu does it). I'm not sure if that's needed for anything other than what I was doing (which I can't remember now), but I just wanted to leave a heads up to anyone using the patch.
Comment #5
xlyz commented#3 works perfectly here. Please commit.
Comment #6
xlyz commentedComment #7
pjcdawkins commentedI'd prefer is_callable() rather than function_exists(), so that anonymous functions or object methods could be used.
Comment #8
pjcdawkins commentedA new patch, with the following modifications to #3:
Comment #9
pjcdawkins commentedNew patch. It turns out 'sanitize' was documented, but since Entity API handles sanitizing I don't understand why it should be there. I think it would be confusing DX to keep it. Also, the docblock in inline_entity_form.api.php (for the hook) needed harmonizing with the one in EntityInlineEntityFormController (for the method).
Comment #10
pjcdawkins commentedSorry, missed out an
array().Comment #11
robertsm commentedHello,
I have tried to use:
When I refresh a webpage nothing happened in IEF table. Any suggestion? When I debuged it with dpm($renderable_data) it shows me #formatter: list_default !
Comment #12
sgurlt commentedHey, for all that come to this problem with date formats, this must look like this:
Comment #13
karolrybak commentedHi I'm using the following code to display node created date. However it is still formatted as timestamp.
Also tried some other combinations though nothing seems to work. Any help is appreciated.
Comment #14
kristofferwiklund commentedPatch does not apply for latest dev version.
Comment #15
kevineinarsson commentedPatch rerolled so it applies to 7.x-1.x.
Comment #16
kevineinarsson commentedComment #17
kevineinarsson commentedComment #21
kristofferwiklund commentedPatch solves problem when displaying "created" date field in inline.
Comment #22
ruslan piskarovThank you, Kristoffer.
I am confirming, your path works for me as well.
Comment #24
ram4nd commented