public function fields($entity = array(), $action = 'all', array $params = array()) {

		$fieldCollection = array();

		$entity = $this->entityFactory->build($entity);
		if ($entity instanceof \ElggEntity) {
			$params['entity'] = $entity;
			$fields = (array) elgg_trigger_plugin_hook('prototype', $action, $params, array());

			$attribute_names = $this->entityFactory->getAttributeNames($entity);
			if (!$entity->guid) {
				$fields['type'] = array('type' => 'hidden');
				$fields['subtype'] = array('type' => 'hidden');
				$fields['owner_guid'] = array('type' => 'hidden');
				$fields['container_guid'] = array('type' => 'hidden');
			} else {
				$fields['guid'] = array('type' => 'hidden');
			}

			foreach ($fields as $shortname => $field) {
				$field['entity_type'] = $entity->getType();
				$field['entity_subtype'] = $entity->getSubtype();
				if (empty($field['shortname'])) {
					$field['shortname'] = $shortname;
				}
				
				if (in_array($shortname, $attribute_names)) {
					$field['data_type'] = 'attribute';
					$field['class_name'] = Elements\AttributeField::CLASSNAME;
				}
				
				$fieldObj = $this->fieldFactory->build($field);
				if ($fieldObj instanceof Elements\Field) {
					$fieldCollection[] = $fieldObj;
				}
			}
		}

		return new Elements\FieldCollection($fieldCollection);
	}