From: Stephen Cameron Date: Wed, 18 Dec 2019 19:29:05 +0000 (+0100) Subject: WIP #3053 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=537d421d7a78c888d7cc73eb8652b89426c69874;p=ccv-wordpress.git WIP #3053 --- diff --git a/wp-content/mu-plugins/cube/src/CPT/Person.php b/wp-content/mu-plugins/cube/src/CPT/Person.php index d6748b6..b58156f 100644 --- a/wp-content/mu-plugins/cube/src/CPT/Person.php +++ b/wp-content/mu-plugins/cube/src/CPT/Person.php @@ -10,7 +10,7 @@ class Person { add_action('typerocket_loaded', function() { $person = \tr_post_type('Person', 'People') ->setIcon('users') - ->setArgument('publicly_queryable', false) // No public page, just used as part of other posts + ->setAdminOnly() // No public page, just used as part of other posts ->setArgument('supports', ['title']) // No editor for this post type ->setTitlePlaceholder('Enter full name here') ->setTitleForm(function() { diff --git a/wp-content/mu-plugins/cube/src/CPT/ScientificNews.php b/wp-content/mu-plugins/cube/src/CPT/ScientificNews.php index a5c9957..a698277 100644 --- a/wp-content/mu-plugins/cube/src/CPT/ScientificNews.php +++ b/wp-content/mu-plugins/cube/src/CPT/ScientificNews.php @@ -2,19 +2,33 @@ namespace Cube\CPT; +use \App\Fields\PostTypeSelect; + class ScientificNews { public function register() { // Wait for TypeRocket to load before adding post type add_action('typerocket_loaded', function() { - $science_news = \tr_post_type('Scientific News') + + // Custom Post Type for Scientific News + \tr_post_type('Scientific News') ->setIcon('flask') - ->setEditorForm(function() { + ->addSupport('post_details'); // Adds meta box "Post Details" that we created below + + // post_details metabox that we put in the right sidebar + \tr_meta_box('Post Details') + ->setContext('side') + ->setCallback(function() { $form = \tr_form(); + + $person = new PostTypeSelect('Published By', $form); + echo $person->setPostType('person'); + echo $form->gallery('Images'); - echo $form->search('Published By')->setPostType('person'); - }); + }); + + }); } diff --git a/wp-content/mu-plugins/typerocket/app/Fields/PostTypeSelect.php b/wp-content/mu-plugins/typerocket/app/Fields/PostTypeSelect.php new file mode 100644 index 0000000..3825dc3 --- /dev/null +++ b/wp-content/mu-plugins/typerocket/app/Fields/PostTypeSelect.php @@ -0,0 +1,43 @@ +setType( 'post_type_select' ); + } + + public function getString() { + + $posts = get_posts([ + 'post_type' => $this->getSetting('post_type'), + 'numberposts' => -1, // Get all posts + 'orderby' => 'post_title', + 'order' => 'ASC', + ]); + + $options = ['' => '(not set)'] + collect($posts)->pluck('post_title', 'ID')->all(); + + $this->setOptions($options, 'flip'); // Flipping the options because the select expects the label as the key + + // Now that the options are set, we can use the normal output of the parent class + return parent::getString(); + } + + /** + * Set the post type to source dropdown options from + * + * @param string $type + * + * @return $this + */ + public function setPostType($type) + { + $this->setSetting('post_type', $type); + return $this; + } + +} diff --git a/wp-content/themes/CCV/app/Composers/ScientificNews.php b/wp-content/themes/CCV/app/Composers/ScientificNews.php new file mode 100644 index 0000000..748fbf8 --- /dev/null +++ b/wp-content/themes/CCV/app/Composers/ScientificNews.php @@ -0,0 +1,62 @@ + $this->published_by(), + 'images' => $this->images(), + ]; + } + + /** + * Returns the images the attributed publisher of the post, if any + * + * @return mixed + */ + public function published_by() + { + $published_by = tr_posts_field('published_by'); + if (!$published_by) return false; + + $person = get_post($published_by); + if (!$person) return false; + + // Get the photo ID if set + $photo = get_post_meta($person->ID, 'photo', true); + + return [ + 'name' => $person->post_title, + 'photo' => $photo, + ]; + } + + /** + * Returns the images attached to this post, if any + * + * @return mixed + */ + public function images() + { + return tr_posts_field('images'); + } +} diff --git a/wp-content/themes/CCV/resources/assets/styles/app.styl b/wp-content/themes/CCV/resources/assets/styles/app.styl index 4c376f9..8705a12 100644 --- a/wp-content/themes/CCV/resources/assets/styles/app.styl +++ b/wp-content/themes/CCV/resources/assets/styles/app.styl @@ -11,7 +11,6 @@ @import 'common/global' @import 'common/admin' @import 'common/layout' -@import 'common/spacing' @import 'common/animations' // MMenu base styles from NPM package @@ -22,6 +21,9 @@ @import 'widgets/*' //@import 'pages/*' +// Allow spacing classes to override others defined here +@import 'common/spacing' + /*! purgecss end ignore */ // Utilities go last in source order so they can diff --git a/wp-content/themes/CCV/resources/assets/styles/common/admin.styl b/wp-content/themes/CCV/resources/assets/styles/common/admin.styl index 0f94c90..9d6db74 100644 --- a/wp-content/themes/CCV/resources/assets/styles/common/admin.styl +++ b/wp-content/themes/CCV/resources/assets/styles/common/admin.styl @@ -1,7 +1,8 @@ // Tiny MCE editor styles in Elementor editor // Most styles for editor set in text-block.styl body... #tinymce - @apply font-body p-3 + @apply font-body + @apply p-3 !important // Normally the lists have no margin and the bullet > image sits // in the spacing gutter created by the text-block. In the context diff --git a/wp-content/themes/CCV/resources/assets/styles/components/news.styl b/wp-content/themes/CCV/resources/assets/styles/components/news.styl index 7cad486..03df582 100644 --- a/wp-content/themes/CCV/resources/assets/styles/components/news.styl +++ b/wp-content/themes/CCV/resources/assets/styles/components/news.styl @@ -2,12 +2,12 @@ &-featured-image @apply bg-cover bg-center - @apply w-full background-color: #ddd constrain(margin-right, 5vw) constrain(margin-bottom, 5vw) max-width: 336px min-width: 150px + flex-basis: 30% &-sizer padding-bottom: 100% diff --git a/wp-content/themes/CCV/resources/views/archive-scientific_news.blade.php b/wp-content/themes/CCV/resources/views/archive-scientific_news.blade.php new file mode 100644 index 0000000..a8f71e1 --- /dev/null +++ b/wp-content/themes/CCV/resources/views/archive-scientific_news.blade.php @@ -0,0 +1,33 @@ +@extends('layouts.app') + +@section('content') + + +
+ +

{{ __('Actualité Scientifique') }}

+ +
+ + @if (! have_posts()) + @alert(['type' => 'warning']) + {{ __('Sorry, no results were found.', 'sage') }} + @endalert + + {!! get_search_form(false) !!} + @endif + + @while (have_posts()) @php(the_post()) + @includeFirst(['partials.content-'.get_post_type(), 'partials.content']) + @endwhile + + {!! get_the_posts_navigation() !!} + +
+ +
+@endsection + +@section('sidebar') + @include('partials.sidebar') +@endsection diff --git a/wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php b/wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php new file mode 100644 index 0000000..b18c050 --- /dev/null +++ b/wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php @@ -0,0 +1,29 @@ +
+ +
+ +
{{-- Just here as a proportional sizer thanks to the padding --}}
+
+
+ +
+

+ + {!! $title !!} + +

+ +
+ @php(the_excerpt()) +
+ +

+ + @svg('arrow', 'h-3 mr-2 fill-current') + + +

+ +
+ +
diff --git a/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php b/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php index 9e9ca50..eb14500 100644 --- a/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php +++ b/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php @@ -2,23 +2,27 @@
-
- {{ __('Publié par') }} -
- {{-- Todo: get linked post type data for user from published_by ID --}} - {{ tr_posts_field('published_by') }} -
- - @foreach(tr_posts_field('images') as $image) -
-
{{-- Just here as a proportional sizer thanks to the padding --}}
+ + @if ($published_by) +
+
+
{{-- Image sizer to make square --}}
+
+ {{ __('Publié par') }} +
+ {{ $published_by['name'] }}
+ @endif + + @foreach($images as $image) + {!! wp_get_attachment_image($image, 'medium', false, ['class' => 'mb-4']) !!} @endforeach
-
-

+
+

{!! $title !!}

diff --git a/wp-content/themes/CCV/resources/views/partials/content.blade.php b/wp-content/themes/CCV/resources/views/partials/content.blade.php index 35e2b2c..f96dafc 100644 --- a/wp-content/themes/CCV/resources/views/partials/content.blade.php +++ b/wp-content/themes/CCV/resources/views/partials/content.blade.php @@ -6,7 +6,7 @@
-
+
@include('partials/entry-meta')