GF_Embed_Config::class, self::EMBED_CONFIG_I18N => GF_Embed_Config_I18N::class, self::EMBED_CONFIG_ENDPOINTS => GF_Embed_Endpoints_Config::class, ); /** * Register services to the container. * * @since 2.6 * * @param GF_Service_Container $container */ public function register( GF_Service_Container $container ) { // Configs require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-embed-config.php' ); require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-embed-config-i18n.php' ); require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-embed-endpoints-config.php' ); // Endpoints require_once( plugin_dir_path( __FILE__ ) . '/endpoints/class-gf-embed-endpoint-get-posts.php' ); require_once( plugin_dir_path( __FILE__ ) . '/endpoints/class-gf-embed-endpoint-create-with-block.php' ); // Dom require_once( plugin_dir_path( __FILE__ ) . '/dom/class-gf-embed-button.php' ); $this->add_configs( $container ); $this->add_endpoints( $container ); $this->dom( $container ); } /** * Initiailize any actions or hooks. * * @since 2.6 * * @param GF_Service_Container $container * * @return void */ public function init( GF_Service_Container $container ) { add_action( 'wp_ajax_' . GF_Embed_Endpoint_Get_Posts::ACTION_NAME, function () use ( $container ) { $container->get( self::ENDPOINT_GET_POSTS )->handle(); } ); add_action( 'wp_ajax_' . GF_Embed_Endpoint_Create_With_Block::ACTION_NAME, function () use ( $container ) { $container->get( self::ENDPOINT_CREATE_WITH_BLOCK )->handle(); } ); add_action( 'gform_before_toolbar_buttons', function () use ( $container ) { $container->get( self::DOM_EMBED_BUTTON )->output_button(); } ); } /** * For each config defined in $configs, instantiate and add to container. * * @since 2.6 * * @param GF_Service_Container $container * * @return void */ private function add_configs( GF_Service_Container $container ) { foreach ( $this->configs as $name => $class ) { $container->add( $name, function () use ( $container, $class ) { return new $class( $container->get( GF_Config_Service_Provider::DATA_PARSER ) ); } ); $container->get( GF_Config_Service_Provider::CONFIG_COLLECTION )->add_config( $container->get( $name ) ); } } /** * Register AJAX endpoints for the Embed UI. * * @since 2.6 * * @param GF_Service_Container $container * * @return void */ private function add_endpoints( GF_Service_Container $container ) { $container->add( self::ENDPOINT_GET_POSTS, function () use ( $container ) { return new GF_Embed_Endpoint_Get_Posts(); } ); $container->add( self::ENDPOINT_CREATE_WITH_BLOCK, function () use ( $container ) { return new GF_Embed_Endpoint_Create_With_Block(); } ); } /** * Register DOM-related services. * * @since 2.6 * * @param GF_Service_Container $container * * @return void */ private function dom( GF_Service_Container $container ) { $container->add( self::DOM_EMBED_BUTTON, function() { return new GF_Embed_Button(); }); } }