Skip to content
Snippets Groups Projects
Commit 023cc800 authored by jaapjansma's avatar jaapjansma
Browse files

Added File URL Type

parent 819b7076
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ Version 1.9 (not yet released)
* Support deleting conditions from actions.
* Fixed issue #15 Errors on import from extensions
* Added File URL Type
Version 1.8
===========
......
......@@ -38,6 +38,7 @@ class Factory {
$this->addType(new FinancialTypeType('FinancialTypeType', E::ts('Financial Type')));
$this->addType(new MembershipTypeType('MembershipTypeType', E::ts('Membership Type')));
$this->addType(new FileType('file', E::ts('File')));
$this->addType(new FileUrlType('file_url', E::ts('File Upload with URL')));
$this->addType(new WeekDays('WeekDays', E::ts('Week Days')));
}
......
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
namespace Civi\FormProcessor\Type;
use \Civi\FormProcessor\Type\GenericType;
use \Civi\FormProcessor\Config\Specification;
use \Civi\FormProcessor\Config\SpecificationBag;
use \CRM_FormProcessor_ExtensionUtil as E;
class FileUrlType extends GenericType {
/**
* Normalize the input value.
*
* @param $value
*
* @return mixed
*/
public function normalizeValue($value) {
if ( $value) {
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$pathinfo = pathinfo($value);
$content = file_get_contents($value);
$normalizedValue['content'] = base64_encode($content);
$normalizedValue['name'] = $pathinfo['basename'];
$normalizedValue['mime_type'] = $finfo->buffer($content);
return $normalizedValue;
}
return $value;
}
/**
* Get the configuration specification.
*
* The configuration is
* format: a string containing the input format.
* see for valid formats
* http://nl1.php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-parameters
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag([]);
}
public function validateValue($value, $allValues = []) {
if (\CRM_Utils_Type::validate($value, 'String', FALSE) === NULL) {
return FALSE;
}
if (filter_var($value, FILTER_VALIDATE_URL) === false) {
return FALSE;
}
return TRUE;
}
/**
* Returns the type number from CRM_Utils_Type
*/
public function getCrmType() {
return \CRM_Utils_Type::T_BLOB;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment