public function handlesEntity(Entity $entity)
 {
     if (!module_exists('webform_validation')) {
         return false;
     }
     if ($entity->type() != 'node') {
         return false;
     }
     if (!in_array($entity->bundle(), webform_node_types())) {
         return false;
     }
     return true;
 }
 public static function getFieldHandlers(Entity $entity, $definition = null, $subtype = false)
 {
     $instances = \field_info_instances($entity->type(), $entity->bundle());
     $handlers = array();
     $handled = array();
     foreach ($instances as $field_name => $instance) {
         $handled[] = $field_name;
         if ($handler = self::getFieldHandler($entity->type(), $field_name, $subtype)) {
             $handlers[$field_name] = $handler;
         }
     }
     // Check special fields on the entity.
     $keys = \entity_get_info($entity->type());
     if (array_key_exists('entity keys', $keys)) {
         foreach ($keys['entity keys'] as $standard => $key) {
             $handled[] = $key;
             if ($handler = self::getTypeHandler($entity->type(), $standard, $subtype)) {
                 $handlers[$key] = $handler;
             }
         }
     }
     // Various other fields.
     foreach ($entity->definition as $key => $value) {
         if (array_search($key, $handled) !== false) {
             continue;
         }
         if ($handler = self::getTypeHandler($entity->type(), $key, $subtype)) {
             $handlers[$key] = $handler;
         }
     }
     // Get other fields on the definition.
     if (is_object($definition) || is_array($definition)) {
         foreach ($definition as $key => $value) {
             if (array_search($key, $handled) !== false) {
                 continue;
             }
             if ($handler = self::getTypeHandler($entity->type(), $key, $subtype)) {
                 $handlers[$key] = $handler;
             }
         }
     }
     return $handlers;
 }
示例#3
0
 /**
  * Copies items that are not associated with the node's revision history over
  * to the new additions array to make sure they are saved every time.
  *
  * @param Entity $entity
  * @param array  $additions
  */
 protected function preserveUnchangingProperties(Entity $entity, array &$additions)
 {
     $properties = publisher_get_unchanging_properties($entity->bundle());
     foreach ($properties as $unchanging_property) {
         if (property_exists($entity->definition, $unchanging_property)) {
             $additions[$unchanging_property] = $entity->definition->{$unchanging_property};
         }
     }
 }