> The option definitions. */ public function options(): array { return array( array( 'key' => 'web_app_url', 'type' => 'url', 'label' => __( 'Web app URL', 'devplugins-custom-form-builder' ), 'placeholder' => 'https://script.google.com/macros/s/…/exec', 'required' => true, ), array( 'key' => 'secret', 'type' => 'password', 'label' => __( 'Shared secret', 'devplugins-custom-form-builder' ), 'description' => __( 'Any phrase. Put the same one in the script, or anybody who learns the URL can add rows.', 'devplugins-custom-form-builder' ), 'required' => true, ), array( 'key' => 'include_meta', 'type' => 'checkbox', 'label' => __( 'Add a date and entry column', 'devplugins-custom-form-builder' ), ), ); } /** * Returns where a submission should be delivered. * * @param Form $form Form being submitted. * @param array $config Stored values for that form. * * @return Webhook|null The endpoint, or null when there is nothing to send to. */ public function endpoint( Form $form, array $config ): ?Webhook { return $this->target( $this->option( $config, 'web_app_url' ) ); } /** * Builds the row and its header. * * Columns and values are sent as two parallel lists rather than as an object, * because a spreadsheet row is positional: the script needs to know that the * third value belongs under the third heading, which an object with an * unspecified key order cannot promise. * * @param IntegrationContext $context Submission being delivered. * @param array $config Stored values for the form. * * @return array The payload. */ public function payload( IntegrationContext $context, array $config ): array { $columns = array(); $row = array(); if ( ! empty( $config['include_meta'] ) ) { $columns[] = __( 'Submitted', 'devplugins-custom-form-builder' ); $columns[] = __( 'Entry', 'devplugins-custom-form-builder' ); $row[] = gmdate( 'c' ); $row[] = $context->submission_id(); } /* * Every field of the form, answered or not, so the columns line up between * one submission and the next. */ foreach ( $context->fields() as $field ) { $key = $field->field_key(); $columns[] = '' !== $field->label() ? $field->label() : $key; $row[] = $context->value( $key ); } return array( 'secret' => $this->option( $config, 'secret' ), 'form' => $context->form()->title(), 'columns' => $columns, 'row' => $row, ); } }