You are here

protected function JuiceboxBaseCase::initFieldInstance in Juicebox HTML5 Responsive Image Galleries 7.2

Helper to setup a file/image field and instance on a specified content type.

Parameters

string $content_type_name: The existing content type machine name to add the field instance to.

string $field_name: The machine name to use for the new field.

string $field_type: The field type for the new field (such as "image" or "file").

string $widget_type: The widget type to use for the new field instance .

3 calls to JuiceboxBaseCase::initFieldInstance()
JuiceboxFileCase::testFile in tests/JuiceboxFileCase.test
Test the field formatter with a file field and file upload widget.
JuiceboxFileCase::testFileNonImage in tests/JuiceboxFileCase.test
Test the non-image handling feature.
JuiceboxFileEntityCase::testFileEntityText in tests/JuiceboxFileEntityCase.test
Test using File Entity fields for gallery titles and captions.

File

tests/JuiceboxBaseCase.test, line 48
Common helper methods for Juicebox module tests.

Class

JuiceboxBaseCase
Common helper class for Juicebox module tests.

Code

protected function initFieldInstance($content_type_name, $field_name, $field_type, $widget_type) {

  // Add a field of type image to the core article type.
  $field_name_friendly = $this
    ->randomName(20);
  $edit = array(
    'fields[_add_new_field][label]' => $field_name_friendly,
    'fields[_add_new_field][field_name]' => $field_name,
    'fields[_add_new_field][type]' => $field_type,
    'fields[_add_new_field][widget_type]' => $widget_type,
  );
  $this
    ->drupalPost('admin/structure/types/manage/' . $content_type_name . '/fields', $edit, t('Save'));

  // We'll go with the default settings for the base.
  $this
    ->drupalPost(NULL, array(), t('Save field settings'));

  // Toggle some options for the instance (depending on the field type) to
  // ensure that caption fields are available.
  $edit = array();
  if ($field_type == 'image') {
    $edit['instance[settings][alt_field]'] = TRUE;
    $edit['instance[settings][title_field]'] = TRUE;
  }
  if ($field_type == 'file') {
    $edit['instance[settings][description_field]'] = TRUE;
    $edit['instance[settings][file_extensions]'] = 'txt,jpg,png,mp3,rtf,docx,pdf';
  }
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));
  $this
    ->assertText(t('Saved @name configuration.', array(
    '@name' => $field_name_friendly,
  )));
  node_types_rebuild();
  menu_rebuild();
  return field_info_instance('node', 'field_' . $field_name, $content_type_name);
}