Skip to content

Commit

Permalink
set icon for file fields #2766
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Nov 19, 2018
1 parent d1f48a5 commit 6baa6fd
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 19 deletions.
17 changes: 11 additions & 6 deletions caldera-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
29 changes: 29 additions & 0 deletions cf2/CalderaFormsV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*
Expand Down
24 changes: 21 additions & 3 deletions cf2/CalderaFormsV2Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -68,8 +89,6 @@ public function getFieldTypeFactory();
*/
public function getWpdb();



/**
* Register a service with container
*
Expand All @@ -83,7 +102,6 @@ public function getWpdb();
*/
public function registerService( ServiceContract $service, $isSingleton );


/**
* Get service from container
*
Expand Down
17 changes: 12 additions & 5 deletions cf2/Fields/FieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}

Expand All @@ -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';
}
}
10 changes: 10 additions & 0 deletions cf2/Fields/FieldTypeContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
10 changes: 8 additions & 2 deletions cf2/Fields/FieldTypes/FileFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
6 changes: 3 additions & 3 deletions classes/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -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' ),
Expand Down
35 changes: 35 additions & 0 deletions tests/Unit/CalderaFormsV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function testGetFieldTypeFactory ()
$this->assertInstanceOf(FieldTypeFactory::class, $containerReal->getFieldTypeFactory());

}

/**
* @since 1.8.0
*
Expand All @@ -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';
Expand All @@ -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
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Fields/RegisterFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') );
}
}

0 comments on commit 6baa6fd

Please sign in to comment.