You are here

protected function SettingsForm::getInstagramApiFields in Instagram Feeds 8

Gets all available for import Instagram post fields.

Parameters

string $field_type: Optional field type to return only supported Instagram fields for.

Return value

array The select field options list.

1 call to SettingsForm::getInstagramApiFields()
SettingsForm::buildMappingForm in src/Form/SettingsForm.php
Form builder for mapping between media entity and Instagram post.

File

src/Form/SettingsForm.php, line 258

Class

SettingsForm
Defines an Instagram Feeds configuration form.

Namespace

Drupal\instagram_feeds\Form

Code

protected function getInstagramApiFields($field_type = '') : array {
  $options = [
    'id' => $this
      ->t('Post ID'),
    'caption' => $this
      ->t('Caption'),
    'username' => $this
      ->t('Owner username'),
    'media_type' => $this
      ->t('Media type (image, video or gallery)'),
    'media_url' => $this
      ->t('Media URL'),
    'permalink' => $this
      ->t('Permalink'),
    'image' => $this
      ->t('Image'),
    'thumbnail_url' => $this
      ->t('Thumbnail URL'),
    'timestamp' => $this
      ->t('UNIX timestamp'),
    'date' => $this
      ->t('Date'),
    'full_name' => $this
      ->t('Owner full name'),
    'avatar' => $this
      ->t('Avatar'),
    'tags' => $this
      ->t('Hash tags'),
  ];
  $strings = [
    'id',
    'username',
    'media_type',
    'media_url',
    'permalink',
    'thumbnail_url',
    'full_name',
    'tags',
  ];
  switch ($field_type) {
    case 'image':
      return array_intersect_key($options, array_fill_keys([
        'avatar',
      ], '1'));
    case 'string':
      return array_intersect_key($options, array_fill_keys($strings, '1'));
    case 'string_long':
      return array_intersect_key($options, array_fill_keys([
        'caption',
      ] + $strings, '1'));
    case 'timestamp':
      return array_intersect_key($options, array_fill_keys([
        'timestamp',
      ], '1'));
    case 'datetime':
      return array_intersect_key($options, array_fill_keys([
        'date',
      ], '1'));
    case 'entity_reference':
      return array_intersect_key($options, array_fill_keys([
        'tags',
      ], '1'));
    case 'ingeger':
      return array_intersect_key($options, array_fill_keys([
        'id',
      ], '1'));
    default:
      return $options;
  }
}