When changing a fields widget type to read only the following error is output.

Notice: String offset cast occured in _field_invoke_multiple() (line 321 of modules/field/field.attach.inc).

It's fine with the hidden option. Using 7.23 and on a long text and summary field with profile2.

Comments

sashkernel’s picture

Any clue what's causing this?
All I have in my case is simply module enabled. Did not do any configure any validation on fields at all yet.

interdruper’s picture

Issue summary: View changes
Status: Active » Needs review

Notice is raised if PHP 5.4+, due to a pending bug in core, see https://drupal.org/node/1824820 .
Until it is fixed, try this workaround: add these 3 lines before line 195:

<?php

    // Workaround for core bug #1824820 until it is fixed.
    // Entity language should be passed as array for not raising a PHP notice
    // in some cases, only if PHP 5.4+.
    $info = entity_get_info($entity_type);
    $cloned_entity->{$info['entity keys']['id']} = 0;
    $cloned_entity->language = array(0 => $cloned_entity->language);

    $element += field_view_field($entity_type, $cloned_entity, $field['field_name'], $display, $langcode);

?>
Jan van Diepen’s picture

We need this patch to be added to our devtrac install profile.

So here's that patch.

james.williams’s picture

Status: Needs review » Closed (outdated)

#1824820: String offset cast notice in field_invoke_method_multiple() was fixed in Drupal core, so this should only be needed on unsupported versions of core. Plus, it causes its own notice(s) on forms for entities that don't have the language property (e.g. terms), so would have needed further work anyway.