diff --git a/caldera-core.php b/caldera-core.php index 59f9b2714..0537c455f 100755 --- a/caldera-core.php +++ b/caldera-core.php @@ -180,18 +180,23 @@ function caldera_forms_fallback_shortcode() * @TODO move this somewhere smarter */ add_action( 'caldera_forms_v2_init', function(\calderawp\calderaforms\cf2\CalderaFormsV2Contract $container){ - $container->setCoreDir(CFCORE_PATH); - //Setup field types - $container->getFieldTypeFactory() + $container + //Set paths + ->setCoreDir(CFCORE_PATH) + ->setCoreUrl(CFCORE_URL ) + + //Setup field types + ->getFieldTypeFactory() ->add( new \calderawp\calderaforms\cf2\Fields\FieldTypes\FileFieldType() ); - //Add hooks + //Add hooks $container->getHooks()->subscribe(); //Register other services - $container->registerService(new \calderawp\calderaforms\cf2\Services\QueueService(),true ); - $container->registerService(new \calderawp\calderaforms\cf2\Services\QueueSchedulerService(),true ); + $container + ->registerService(new \calderawp\calderaforms\cf2\Services\QueueService(),true ) + ->registerService(new \calderawp\calderaforms\cf2\Services\QueueSchedulerService(),true ); //Run the scheduler with CRON /** @var \calderawp\calderaforms\cf2\Jobs\Scheduler $scheduler */ diff --git a/cf2/CalderaFormsV2.php b/cf2/CalderaFormsV2.php index 5731b947c..49cda7dab 100644 --- a/cf2/CalderaFormsV2.php +++ b/cf2/CalderaFormsV2.php @@ -19,6 +19,14 @@ class CalderaFormsV2 extends \calderawp\CalderaContainers\Service\Container impl */ protected $coreDirPath; + /** + * URL for main plugin file + * + * @since 1.8.0 + * + * @var string + */ + protected $coreUrl; /** * CalderaFormsV2 constructor. @@ -105,6 +113,27 @@ public function getCoreDir(){ return ''; } + /* @inheritdoc */ + public function setCoreUrl($coreUrl) + { + $this->coreUrl = $coreUrl; + return $this; + } + + /** @inheritdoc */ + public function getCoreUrl() + { + if( $this->coreUrl ){ + return $this->coreUrl; + } + + if( defined( 'CFCORE_URL') ){ + return CFCORE_URL; + } + + return ''; + } + /** * Get the singleton hooks instance * diff --git a/cf2/CalderaFormsV2Contract.php b/cf2/CalderaFormsV2Contract.php index d69393aba..a0c2a08e9 100644 --- a/cf2/CalderaFormsV2Contract.php +++ b/cf2/CalderaFormsV2Contract.php @@ -50,6 +50,27 @@ public function setCoreDir($coreDirPath); */ public function getCoreDir(); + + /** + * Set URL to main plugin file + * + * @since 1.8.0 + * + * @param string $coreUrl + * + * @return $this + */ + public function setCoreUrl($coreUrl); + + /** + * Get URL path to main plugin file + * + * @since 1.8.0 + * + * @return string + */ + public function getCoreUrl(); + /** * Get field type factory * @@ -68,8 +89,6 @@ public function getFieldTypeFactory(); */ public function getWpdb(); - - /** * Register a service with container * @@ -83,7 +102,6 @@ public function getWpdb(); */ public function registerService( ServiceContract $service, $isSingleton ); - /** * Get service from container * diff --git a/cf2/Fields/FieldType.php b/cf2/Fields/FieldType.php index 5e6c0803e..692eef355 100644 --- a/cf2/Fields/FieldType.php +++ b/cf2/Fields/FieldType.php @@ -11,11 +11,12 @@ abstract class FieldType implements FieldTypeContract public static function toArray () { return [ - "cf2" => TRUE, - "field" => static::getName(), - "description" => static::getDescription(), - "category" => static::getCategory(), - "setup" => static::getSetup(), + 'cf2' => TRUE, + 'field' => static::getName(), + 'description' => static::getDescription(), + 'category' => static::getCategory(), + 'setup' => static::getSetup(), + 'icon' => static ::getIcon(), ]; } @@ -27,4 +28,10 @@ public static function getSetup () 'preview' => 'fields/' . static::getCf1Identifier() . '/preview.php', ]; } + + /** @inheritdoc */ + public static function getIcon() + { + return caldera_forms_get_v2_container()->getCoreUrl() . 'assets/build/images/field.png'; + } } diff --git a/cf2/Fields/FieldTypeContract.php b/cf2/Fields/FieldTypeContract.php index 8fada995d..c9ec9a8dc 100644 --- a/cf2/Fields/FieldTypeContract.php +++ b/cf2/Fields/FieldTypeContract.php @@ -68,4 +68,14 @@ public static function getName(); * @return array */ public static function toArray(); + + + /** + * Get field type icon + * + * @since 1.8.0 + * + * @return string + */ + public static function getIcon(); } diff --git a/cf2/Fields/FieldTypes/FileFieldType.php b/cf2/Fields/FieldTypes/FileFieldType.php index 84bd4dbc7..e61071124 100644 --- a/cf2/Fields/FieldTypes/FileFieldType.php +++ b/cf2/Fields/FieldTypes/FileFieldType.php @@ -28,12 +28,18 @@ public static function getCategory () /** @inheritdoc */ public static function getDescription () { - return __( 'File Field With Super Powers', 'caldera-forms' ); + return __( 'File upload field with more features than standard HTML5 input.', 'caldera-forms' ); } /** @inheritdoc */ public static function getName () { - return __( 'File Field (CF2)', 'caldera-forms' ); + return __( 'Advanced File Uploader (2.0)', 'caldera-forms' ); + } + + /** @inheritdoc */ + public static function getIcon() + { + return caldera_forms_get_v2_container()->getCoreUrl() . 'assets/images/cloud-upload.svg'; } } diff --git a/classes/fields.php b/classes/fields.php index 21e7d33ec..104c54e0e 100755 --- a/classes/fields.php +++ b/classes/fields.php @@ -403,7 +403,7 @@ public static function internal_types() { //file 'file' => array( "field" => __( 'File', 'caldera-forms' ), - "description" => __( 'File Uploader', 'caldera-forms' ), + "description" => __( 'Basic HTML5 File Uploader', 'caldera-forms' ), "file" => CFCORE_PATH . "fields/file/field.php", 'icon' => CFCORE_URL . 'assets/build/images/cloud-upload.svg', "viewer" => array( Caldera_Forms::get_instance(), 'handle_file_view' ), @@ -414,9 +414,9 @@ public static function internal_types() { ) ), 'advanced_file' => array( - "field" => __( 'Advanced File Uploader', 'caldera-forms' ), + "field" => __( 'Advanced File Uploader (1.0)', 'caldera-forms' ), 'icon' => CFCORE_URL . 'assets/build/images/cloud-upload.svg', - "description" => __( 'Inline, multi file uploader', 'caldera-forms' ), + "description" => __( 'File upload field with more features than standard HTML5 input.', 'caldera-forms' ), "file" => CFCORE_PATH . "fields/advanced_file/field.php", "viewer" => array( Caldera_Forms::get_instance(), 'handle_file_view' ), "category" => __( 'File', 'caldera-forms' ), diff --git a/tests/Unit/CalderaFormsV2Test.php b/tests/Unit/CalderaFormsV2Test.php index 4b4de685c..54cf68b52 100644 --- a/tests/Unit/CalderaFormsV2Test.php +++ b/tests/Unit/CalderaFormsV2Test.php @@ -52,6 +52,7 @@ public function testGetFieldTypeFactory () $this->assertInstanceOf(FieldTypeFactory::class, $containerReal->getFieldTypeFactory()); } + /** * @since 1.8.0 * @@ -71,6 +72,7 @@ public function testSetCorDir(){ * @since 1.8.0 * * @covers \calderawp\calderaforms\cf2\CalderaFormsV2::getCoreDir(); + * @covers \calderawp\calderaforms\cf2\CalderaFormsV2::$coreDirPath; */ public function testGetCorDir(){ $coreDir = 'foo/bar'; @@ -83,6 +85,39 @@ public function testGetCorDir(){ } + /** + * @since 1.8.0 + * + * @covers \calderawp\calderaforms\cf2\CalderaFormsV2::setCoreUrl(); + * @covers \calderawp\calderaforms\cf2\CalderaFormsV2::$coreUrl + */ + public function testSetCorUrl(){ + $coreUrl = 'https://example.com/wp-content/plugins/foo'; + $containerMock = $this->getContainer(); + $containerMock->setCoreUrl($coreUrl); + $this->assertAttributeEquals( $coreUrl, 'coreUrl', $containerMock ); + $containerReal = new CalderaFormsV2(); + $containerReal->setCoreUrl($coreUrl); + $this->assertAttributeEquals( $coreUrl, 'coreUrl', $containerReal ); + } + + /** + * @since 1.8.0 + * + * @covers \calderawp\calderaforms\cf2\CalderaFormsV2::setCoreUrl(); + * @covers \calderawp\calderaforms\cf2\CalderaFormsV2::$coreUrl + */ + public function testGetCorUrl(){ + $coreUrl = 'https://example.com/wp-content/plugins/foo'; + $containerMock = $this->getContainer(); + $containerMock->setCoreUrl($coreUrl); + $this->assertEquals( $coreUrl, $containerMock->getCoreUrl() ); + $containerReal = new CalderaFormsV2(); + $containerReal->setCoreUrl($coreUrl); + $this->assertEquals( $coreUrl, $containerReal->getCoreUrl() ); + } + + /** * Test service registration * diff --git a/tests/Unit/Fields/RegisterFieldsTest.php b/tests/Unit/Fields/RegisterFieldsTest.php index cb38a4bc7..83cc015cf 100644 --- a/tests/Unit/Fields/RegisterFieldsTest.php +++ b/tests/Unit/Fields/RegisterFieldsTest.php @@ -76,4 +76,13 @@ public function testFilterAddsFullPath () $this->assertTrue(0 === strpos($setup[ 'template' ], $path)); } + + /** + * @since 1.8.0 + * + * @covers \calderawp\calderaforms\cf2\Fields\FieldTypes\FileFieldType() + */ + public function testFileFieldIcon(){ + $this->assertNotFalse( strpos( FileFieldType::getIcon(), 'cloud-upload.svg') ); + } }