-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ademarco/field-handlers
Field handling implementation for API driver Signed-off-by: Jonathan Hedstrom <[email protected]>
- Loading branch information
Showing
21 changed files
with
587 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Driver\Cores\AbstractCore | ||
*/ | ||
|
||
namespace Drupal\Driver\Cores; | ||
|
||
use Symfony\Component\DependencyInjection\Container; | ||
|
||
abstract class AbstractCore implements CoreInterface { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getFieldHandler($entity_type, $field_name) { | ||
|
||
$reflection = new \ReflectionClass($this); | ||
$core_namespace = $reflection->getShortName(); | ||
$field_types = $this->getEntityFieldTypes($entity_type); | ||
$camelized_type = Container::camelize($field_types[$field_name]); | ||
$default_class = sprintf('\Drupal\Driver\Fields\%s\DefaultHandler', $core_namespace); | ||
$class_name = sprintf('\Drupal\Driver\Fields\%s\%sHandler', $core_namespace, $camelized_type); | ||
if (class_exists($class_name)) { | ||
return new $class_name($entity_type, $field_name); | ||
} | ||
return new $default_class($entity_type, $field_name); | ||
} | ||
|
||
/** | ||
* Given a entity, expand fields to match the format expected by entity_save(). | ||
* | ||
* @param \stdClass $entity | ||
* Entity object. | ||
* @return \stdClass | ||
* Entity object. | ||
*/ | ||
protected function expandEntityFields($entity_type, \stdClass $entity) { | ||
|
||
$field_types = $this->getEntityFieldTypes($entity_type); | ||
foreach ($field_types as $field_name => $type) { | ||
if (isset($entity->$field_name)) { | ||
$entity->$field_name = $this->getFieldHandler($entity_type, $field_name)->expand($entity->$field_name); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Driver\Fields\Drupal7\AbstractFieldHandler | ||
*/ | ||
|
||
namespace Drupal\Driver\Fields\Drupal7; | ||
|
||
use Drupal\Driver\Fields\FieldHandlerInterface; | ||
|
||
abstract class AbstractHandler implements FieldHandlerInterface { | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $field_info = array(); | ||
|
||
/** | ||
* Get field instance information. | ||
* | ||
* @param $field_name | ||
* @return mixed | ||
*/ | ||
public function __construct($entity_type, $field_name) { | ||
$this->field_info = field_info_field($field_name); | ||
} | ||
|
||
} |
Oops, something went wrong.