You are here

function paragraphs_pack_add_field_file in Paragraphs pack 7

Adds file field to a paragraph bundle.

Parameters

string $bundle: A paragraph type machine_name.

string $field_label: A label of the field.

array $settings: An instance settings that overrides default settings. Default settings are commented in this function, so all the options can be found there.

Return value

array An items field instance.

1 call to paragraphs_pack_add_field_file()
ParagraphsPackTestCase::testParagraphsPackFieldFileInstanceCreation in tests/paragraphs_pack.test
Test function for field file instance creation.

File

includes/paragraphs_pack.fields_crud.inc, line 275
Fields CRUD functions.

Code

function paragraphs_pack_add_field_file($bundle, $field_label, $settings) {
  $field = paragraphs_pack_get_field_file();

  // Default settings with all possible options.
  $settings_default = array(
    'file_extensions' => 'png jpg',
  );

  // Add default settings if some options are missing
  $settings += $settings_default;
  $instance = _paragraphs_pack_add_field(array(
    'field_name' => $field['field_name'],
    'entity_type' => PP_PARAGRAPH_TYPE,
    'bundle' => $bundle,
    'label' => $field_label,
    'required' => 1,
    'settings' => $settings,
  ));
  return $instance;
}