generator-folklore 3.0.21 → 3.0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,8 @@ use Illuminate\Http\Resources\Json\JsonResource;
6
6
  use Folklore\Contracts\Resources\HasBlocks;
7
7
  use Folklore\Http\Resources\LocalizedResource;
8
8
  use App\Contracts\Resources\Blocks\Text as TextBlock;
9
+ use App\Contracts\Resources\Blocks\ImageBlock as ImageBlock;
10
+ use Folklore\Http\Resources\MediaResource;
9
11
 
10
12
  class BlockResource extends JsonResource
11
13
  {
@@ -18,7 +20,6 @@ class BlockResource extends JsonResource
18
20
  public function toArray($request)
19
21
  {
20
22
  $type = $this->type();
21
- $locale = $request->locale();
22
23
  return [
23
24
  'id' => $this->id(),
24
25
  'type' => $type,
@@ -27,9 +28,27 @@ class BlockResource extends JsonResource
27
28
  return !is_null($blocks) ? new BlocksCollection($blocks) : [];
28
29
  }),
29
30
 
30
- $this->mergeWhen($this->resource instanceof TextBlock, function () use ($locale) {
31
+ $this->mergeWhen($this->resource instanceof TextBlock, function () {
31
32
  return [
32
- 'body' => $this->body($locale),
33
+ 'title' => new LocalizedResource(function ($locale) {
34
+ return $this->title($locale);
35
+ }),
36
+ 'body' => new LocalizedResource(function ($locale) {
37
+ return $this->body($locale);
38
+ }),
39
+ ];
40
+ }),
41
+
42
+ $this->mergeWhen($this->resource instanceof ImageBlock, function () {
43
+ $image = $this->image();
44
+ return [
45
+ 'image' => !empty($image) ? new MediaResource($image) : null,
46
+ 'caption' => new LocalizedResource(function ($locale) {
47
+ return $this->caption($locale);
48
+ }),
49
+ 'credits' => new LocalizedResource(function ($locale) {
50
+ return $this->credits($locale);
51
+ }),
33
52
  ];
34
53
  }),
35
54
  ];
@@ -11,7 +11,7 @@ class Block extends BaseBlock
11
11
  {
12
12
  use HasFactory;
13
13
 
14
- protected $typeResources = [
14
+ protected $typedResources = [
15
15
  'text' => \App\Resources\Blocks\TextBlock::class,
16
16
  'image' => \App\Resources\Blocks\ImageBlock::class,
17
17
  ];
@@ -19,4 +19,9 @@ class Page extends BasePage
19
19
  {
20
20
  return $this->toTypedResource() ?? new PageResource($this);
21
21
  }
22
+
23
+ public function blocks()
24
+ {
25
+ return $this->morphToMany(Block::class, 'blockable', 'blocks_pivot');
26
+ }
22
27
  }
@@ -3,9 +3,11 @@
3
3
  namespace App\Panneau\Http\Resources;
4
4
 
5
5
  use Illuminate\Http\Resources\Json\JsonResource;
6
- use App\Contracts\Resources\HasBlocks;
6
+ use Folklore\Contracts\Resources\HasBlocks;
7
7
  use Folklore\Http\Resources\LocalizedResource;
8
8
  use App\Contracts\Resources\Blocks\Text as TextBlock;
9
+ use App\Contracts\Resources\Blocks\Image as ImageBlock;
10
+ use Folklore\Http\Resources\MediaResource;
9
11
 
10
12
  class BlockResource extends JsonResource
11
13
  {
@@ -18,7 +20,6 @@ class BlockResource extends JsonResource
18
20
  public function toArray($request)
19
21
  {
20
22
  $type = $this->type();
21
-
22
23
  return [
23
24
  'id' => $this->id(),
24
25
  'type' => $type,
@@ -29,11 +30,27 @@ class BlockResource extends JsonResource
29
30
 
30
31
  $this->mergeWhen($this->resource instanceof TextBlock, function () {
31
32
  return [
33
+ 'title' => new LocalizedResource(function ($locale) {
34
+ return $this->title($locale);
35
+ }),
32
36
  'body' => new LocalizedResource(function ($locale) {
33
37
  return $this->body($locale);
34
38
  }),
35
39
  ];
36
40
  }),
41
+
42
+ $this->mergeWhen($this->resource instanceof ImageBlock, function () {
43
+ $image = $this->image();
44
+ return [
45
+ 'image' => !empty($image) ? new MediaResource($image) : null,
46
+ 'caption' => new LocalizedResource(function ($locale) {
47
+ return $this->caption($locale);
48
+ }),
49
+ 'credits' => new LocalizedResource(function ($locale) {
50
+ return $this->credits($locale);
51
+ }),
52
+ ];
53
+ }),
37
54
  ];
38
55
  }
39
56
  }
@@ -1,12 +1,13 @@
1
- import React, { useState, useEffect } from 'react';
2
- import PropTypes from 'prop-types';
3
- import Panneau from '@panneau/app';
4
1
  import { getCSRFHeaders } from '@folklore/fetch';
5
-
2
+ import Panneau from '@panneau/app';
6
3
  import { FIELDS_NAMESPACE } from '@panneau/core/contexts';
7
- import * as fieldsComponents from './panneau/fields';
4
+ import PropTypes from 'prop-types';
5
+ import React, { useState, useEffect } from 'react';
6
+
8
7
  import * as AppPropTypes from '../lib/PropTypes';
9
8
 
9
+ import * as fieldsComponents from './panneau/fields';
10
+
10
11
  import '../../styles/panneau.scss';
11
12
 
12
13
  const propTypes = {
@@ -26,7 +27,6 @@ const defaultProps = {
26
27
  const PanneauContainer = ({ definition, user, baseUrl, uploadEndpoint, statusCode }) => {
27
28
  const { routes = {} } = definition;
28
29
  const isAuthorized = statusCode !== 401 && statusCode !== 403;
29
-
30
30
  const [localeLoaded, setLocaleLoaded] = useState(false);
31
31
 
32
32
  useEffect(() => {
@@ -1,2 +1,4 @@
1
+ @import '~@panneau/app/scss/styles';
2
+
1
3
  @import '~@panneau/themes/scss/styles';
2
4
  @import '~@panneau/themes/scss/vendor';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-folklore",
3
- "version": "3.0.21",
3
+ "version": "3.0.22",
4
4
  "description": "Yeoman generator for projects at Folklore",
5
5
  "keywords": [
6
6
  "yeoman-generator"
@@ -40,5 +40,5 @@
40
40
  "yeoman-generator": "^5.7.0",
41
41
  "yeoman-remote": "^1.0.1"
42
42
  },
43
- "gitHead": "e187175793ce4d11d128d39929b4779c534081bd"
43
+ "gitHead": "299c4d804aaa15455627b5ae353d3936da9fd692"
44
44
  }