+ /**
+ * Convert an entity to a raw data array of input data.
+ *
+ * @return array<string, mixed>
+ */
+ public function entityToInputData(Entity $entity): array
+ {
+ $inputData = $entity->getAttributes();
+ $inputData['tags'] = $this->entityTagsToInputArray($entity);
+
+ // Add a cover to the data if existing on the original entity
+ if ($entity instanceof HasCoverImage) {
+ $cover = $entity->cover()->first();
+ if ($cover) {
+ $inputData['image'] = $this->imageToUploadedFile($cover);
+ }
+ }
+
+ return $inputData;
+ }
+
+ /**
+ * Copy the permission settings from the source entity to the target entity.
+ */
+ public function copyEntityPermissions(Entity $sourceEntity, Entity $targetEntity): void
+ {
+ $permissions = $sourceEntity->permissions()->get(['role_id', 'view', 'create', 'update', 'delete'])->toArray();
+ $targetEntity->permissions()->delete();
+ $targetEntity->permissions()->createMany($permissions);
+ $targetEntity->rebuildPermissions();
+ }
+