Hi there
Is there any Tutorial that shows me as a non-rocket-engineer how to ad a simple custom field?
i need an field that stores the opening hours in plain text!

What i tried:
A) using the example module
1) I cloned the example folder adressfield/example => myAddressField
to my module directory.
2) renamed addressfield_example.module => myAddressField.module
3) renamed addressfield_example.info => myAddressField.info
4) changed the name in myAddressField.info => myAddress Field

drush cc all

then i tried to find this module in my modules list
admin/modules
to enable it.
but the module did not show up there !?!

B) using a clone from an existing plugin format
1) clones addressfiled/plugins/format/organisation.inc => addressfiled/plugins/format/organisation2.inc
2) changed the code from organisation.inc like following:

/**
 * @file
 * Generates a first name + last name format.
 */

$plugin = array(
  'title' => t('Organisation 2 (single line)'),
  'format callback' => 'addressfield_format_organisation2_generate',
  'type' => 'organisation',
  'weight' => -10,
);

/**
 * Format callback.
 *
 * @see CALLBACK_addressfield_format_callback()
 */
function addressfield_format_organisation2_generate(&$format, $address) {
  $format['organisation2_block'] = array(
    '#type' => 'addressfield_container',
    '#attributes' => array('class' => array('addressfield-container-inline', 'name-block')),
    '#weight' => -50,
    // The addressfield is considered empty without a country, hide all fields
    // until one is selected.
    '#access' => !empty($address['country']),
  );
  $format['organisation2_block']['organisation_name'] = array(
    '#title' => t('Company 2'),
    '#size' => 30,
    '#maxlength' => 255,
    '#attributes' => array(
      'class' => array('organisation2-name'),
      'autocomplete' => 'organization2',
    ),
  );
}

3) drush cc all

4) the field is now available in the field settings and also in the node edit form.
but its not possible to store date!
so, what ic can see now is that my field needs to set up in the function addressfield_field_schema() {}
to be stored.
but where do i have to exand the addressfield_field_schema() ?
in a custom module?
or do i miss something?

very thankfull for any hint!
best regards

Comments

1kubik created an issue. See original summary.

bojanz’s picture

Status: Active » Fixed

You should not be doing this at all. Add the custom field to your parent entity, the one that has the addressfield attached.

In the Commerce case it's the customer profile, in yours it might be a node, etc.

1kubik’s picture

hi bojnaz
thank you for your answer!
the point is that i have a multiple amount of an addressfields attached to a node
and each adressfield needs an extra field (e.g.: opening hours)

how can i achiev this in wich way?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.