<?php // $file = /home/bluedoor/www/dev/wp-content/plugins/yooessentials/modules/form/actions/SaveDatabase/config.json

return [
  'name' => 'save-database', 
  'title' => 'Save to Database', 
  'group' => 'data', 
  'description' => 'Save data to a Database table.', 
  'icon' => $filter->apply('url', '~yooessentials_url/modules/form/actions/SaveDatabase/icon.svg', $file), 
  'fields' => [
    'external' => [
      'text' => 'With Custom Connection', 
      'type' => 'checkbox', 
      'default' => false
    ], 
    'table' => [
      'label' => 'Table', 
      'type' => 'yooessentials-select-dropdown-async', 
      'endpoint' => 'yooessentials/form-action/savedb/tables', 
      'description' => 'The table where the submission data will be appended to.'
    ], 
    'table_key' => [
      'label' => 'Associative Key', 
      'type' => 'yooessentials-select-dropdown-async', 
      'endpoint' => 'yooessentials/form-action/savedb/fields'
    ], 
    'table_key_value' => [
      'label' => 'Value', 
      'source' => true, 
      'sourceOmitOrigin' => ['query.page']
    ], 
    'update_if_exists' => [
      'text' => 'Update record if already exists', 
      'type' => 'checkbox'
    ], 
    'content' => [
      'label' => 'Content', 
      'type' => 'yooessentials-dataset-mapping', 
      'description' => 'The content for each table column.', 
      'endpoint' => 'yooessentials/form-action/savedb/columns', 
      'watch' => 'table', 
      'enable' => 'table', 
      'panel' => [
        'title' => 'Content', 
        'fields' => [
          'value' => [
            'label' => 'Value', 
            'source' => true, 
            'sourceOmitOrigin' => ['query.page'], 
            'enable' => '!set_null'
          ], 
          'set_null' => [
            'text' => 'Set as Null', 
            'type' => 'checkbox', 
            'default' => false
          ], 
          'skip_if_empty' => [
            'text' => 'Skip if value is empty', 
            'type' => 'checkbox', 
            'default' => false
          ]
        ]
      ]
    ], 
    'db_name' => $config->get('yooessentials.core.fields.db.name'), 
    'db_connection' => [
      'label' => 'Connection', 
      'show' => 'external', 
      'type' => 'yooessentials-connected-auth', 
      'connections' => [
        'database' => []
      ], 
      'description' => 'The database connection to use.'
    ], 
    'name' => $config->get('yooessentials.form.fields.action_name'), 
    'status' => $config->get('yooessentials.form.fields.action_status'), 
    'conditions' => $config->get('yooessentials.form.fields.action_conditions')
  ], 
  'fieldset' => [
    'default' => [
      'type' => 'tabs', 
      'fields' => [[
          'title' => 'Action', 
          'fields' => ['db_name', 'external', 'db_connection', 'table', 'update_if_exists', [
              'name' => '_update', 
              'type' => 'grid', 
              'width' => '1-2', 
              'description' => 'The key and value that will associate the submission with an existing record.', 
              'show' => 'update_if_exists && table', 
              'fields' => ['table_key', 'table_key_value']
            ], 'content']
        ], [
          'title' => 'Advanced', 
          'fields' => ['name', 'status', 'conditions']
        ]]
    ]
  ]
];
