Custom entity mit entity api, Felderproblem aber ich weiß nicht wo!
am 10.09.2014 - 12:14 Uhr in
Ich habe ein test Module mit Namen demo, in dem ich ein Custom Entity mit Namen Projekt habe. Das Ding kan das volle CRUD und ist in views integriert. Läuft sozusagen.
Aber:
Ich möchte das als Entity Reference mit dem Modul Inline Entity Form integrieren, was laut allgemeiner Aussage in der README des Moduls auch möglich sein soll.
Irgendwie habe ich aber ein Feld Problem, da die Funktion des Moduls "tableFields", die dafür zuständig ist die entsprechenden Felder der Entity zu verarbeiten, nichts beim debuggen auswirft.
Zur Funktion steht im Modul folgendes:
* Returns an array of fields used to represent an entity in the IEF table.
*
* The fields can be either Field API fields or properties defined through
* hook_entity_property_info().
*
* Modules can alter the output of this method through
* hook_inline_entity_form_table_fields_alter().
*
Aber nix! Alle jetzt vorkommenden Codes stehen direkt in der demo.module:
/**
* Implements hook_entity_property_info().
*/
function demo_entity_property_info() {
$info = array();
$info['project']['properties']['id'] = array(
'label' => t('Project ID'),
'description' => t('The ID of the project.'),
'type' => 'integer',
'schema field' => 'id',
);
$info['project']['properties']['name'] = array(
'label' => t('Project name'),
'description' => t('Name of the project.'),
'type' => 'text',
'schema field' => 'name',
);
$info['project']['properties']['description'] = array(
'label' => t('Project description'),
'description' => t('Description of the project.'),
'type' => 'text',
'schema field' => 'description',
);
$info['project']['properties']['deadline'] = array(
'label' => t('Deadline'),
'description' => t('Project deadline.'),
'type' => 'date',
'schema field' => 'deadline',
);
return $info;
}
Der Code läuft weil ich damit auch views ansprechen kann.
Dann dachte ich lese ich halt mal das gesamte Internet durch, was es noch sein könnte. Deshalb kam ich dann auf die Idee die Felder noch mal in drupal förmlich anzumelden.
Habe es testweise für ein Feld gemacht:
/**
* Implements hook_field_info to make it work with Entity Meta Wrappers
* Provides the description of the field.
*/
function demo_field_info() {
$demo_fields = array(
// We name our field as the associative name of the array.
'name' => array(
'label' => t('Project name'),
'description' => t('Name of the project.'),
'settings' => array('max_length' => 255),
'instance_settings' => array('text_processing' => 0),
'default_widget' => 'text_textfield',
'default_formatter' => 'text_default',
'property_type' => 'text', // we add the propert type here
),
);
return $demo_fields;
}
Wenn ich aber den debugger drüber laufen lasse wird die Funktion weiter tapfer ignoriert. Trotzdem habe ich sie mal überschrieben in der Hoffnung dass das was nützt. Auf die Idee bin ich durch das line_item Modul gekommen für commerce:
/**
* Overrides EntityInlineEntityFormController::tableFields().
*/
public function tableFields($bundles) {
$fields = array();
$fields['project']['properties']['id'] = array(
'label' => t('Project ID'),
'description' => t('The ID of the project.'),
'type' => 'integer',
'schema field' => 'id',
);
$fields['project']['properties']['name'] = array(
'label' => t('Project name'),
'description' => t('Name of the project.'),
'type' => 'text',
'schema field' => 'name',
);
$fields['project']['properties']['description'] = array(
'label' => t('Project description'),
'description' => t('Description of the project.'),
'type' => 'text',
'schema field' => 'description',
);
$fields['project']['properties']['deadline'] = array(
'label' => t('Deadline'),
'description' => t('Project deadline.'),
'type' => 'date',
'schema field' => 'deadline',
);
return $fields;
}
Dann immer noch nix. So dachte ich mir, ignoriere das mal und baue ne form, vielleicht kriege ich darin dann die nötigen Felder zu Gesicht:
/**
* Overrides EntityInlineEntityFormController::entityForm().
*/
public function entityForm($entity_form, &$form_state) {
$term = $entity_form['#entity'];
return 'is mir egal';
}
}
Daher denke ich dass ich irgendwas bei der Erstellung der custom entity übersehen habe. Hat da jemand Efahrung oder eine Idee?
Danke vorab,
Marc
- Anmelden oder Registrieren um Kommentare zu schreiben
Neue Kommentare
vor 4 Tagen 20 Stunden
vor 1 Woche 18 Stunden
vor 1 Woche 20 Stunden
vor 1 Woche 20 Stunden
vor 1 Woche 20 Stunden
vor 1 Woche 22 Stunden
vor 1 Woche 2 Tagen
vor 1 Woche 2 Tagen
vor 1 Woche 2 Tagen
vor 1 Woche 2 Tagen