]> _ Git - ccv-wordpress.git/commitdiff
WIP #3053
authorStephen Cameron <stephen@cubedesigners.com>
Wed, 18 Dec 2019 19:29:05 +0000 (20:29 +0100)
committerStephen Cameron <stephen@cubedesigners.com>
Wed, 18 Dec 2019 19:29:05 +0000 (20:29 +0100)
wp-content/mu-plugins/cube/src/CPT/Person.php
wp-content/mu-plugins/cube/src/CPT/ScientificNews.php
wp-content/mu-plugins/typerocket/app/Fields/PostTypeSelect.php [new file with mode: 0644]
wp-content/themes/CCV/app/Composers/ScientificNews.php [new file with mode: 0644]
wp-content/themes/CCV/resources/assets/styles/app.styl
wp-content/themes/CCV/resources/assets/styles/common/admin.styl
wp-content/themes/CCV/resources/assets/styles/components/news.styl
wp-content/themes/CCV/resources/views/archive-scientific_news.blade.php [new file with mode: 0644]
wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php [new file with mode: 0644]
wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php
wp-content/themes/CCV/resources/views/partials/content.blade.php

index d6748b6eb32519ef43342c130b051e6e77ead215..b58156f5381244d9960a214870f5aee6fb6a6564 100644 (file)
@@ -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() {
index a5c9957d4ad9f58f3eb7ed32453abb30c2ebdb6c..a6982770738f2d2802f48f0770589aa2321989f7 100644 (file)
@@ -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 (file)
index 0000000..3825dc3
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Fields;
+
+use TypeRocket\Elements\Fields\Select;
+
+class PostTypeSelect extends Select
+{
+    protected function init() {
+        $this->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 (file)
index 0000000..748fbf8
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Composers;
+
+use Roots\Acorn\View\Composer;
+
+class ScientificNews extends Composer
+{
+    /**
+     * List of views served by this composer.
+     *
+     * @var array
+     */
+    protected static $views = [
+        'partials.content-single-scientific_news',
+    ];
+
+    /**
+     * Data to be passed to view before rendering.
+     *
+     * @return array
+     */
+    public function with()
+    {
+        return [
+            'published_by' => $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');
+    }
+}
index 4c376f9c2278bb7b6cac022475a46351c5ce01f6..8705a12eb83f1b706d2d43eb7523c4e656589475 100644 (file)
@@ -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
index 0f94c90a67c073aada173170063b924b562e4995..9d6db74c3b202560bbf6326ab93fc6d804c738c6 100644 (file)
@@ -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
index 7cad486e5499b9b9f7774cfe6db0296880083f2d..03df58272ccf792e943e01fd4b260f208693b9a9 100644 (file)
@@ -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 (file)
index 0000000..a8f71e1
--- /dev/null
@@ -0,0 +1,33 @@
+@extends('layouts.app')
+
+@section('content')
+
+
+  <div class="bg-light py-2v px-4v">
+
+    <h1 class="h2">{{ __('Actualité Scientifique') }}</h1>
+
+    <div class="mt-2v">
+
+      @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() !!}
+
+    </div>
+
+  </div>
+@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 (file)
index 0000000..b18c050
--- /dev/null
@@ -0,0 +1,29 @@
+<article @php(post_class('flex items-start mt-1v sm:block sm:mt-12'))>
+
+  <div class="post-featured-image min-w-0 mr-1v mb-1v" style="background-image: url({{ get_the_post_thumbnail_url() }}); max-width: 135px;">
+    <a href="{{ get_permalink() }}">
+      <div class="post-featured-image-sizer">{{-- Just here as a proportional sizer thanks to the padding --}}</div>
+    </a>
+  </div>
+
+  <header style="flex-basis: 100%">
+    <h2 class="plain text-lg mb-2">
+      <a href="{{ get_permalink() }}">
+        {!! $title !!}
+      </a>
+    </h2>
+
+    <div class="entry-summary">
+      @php(the_excerpt())
+    </div>
+
+    <p class="mt-6 mb-1v">
+      <a class="uppercase text-pink inline-flex items-center" href="{{ get_permalink() }}">
+        @svg('arrow', 'h-3 mr-2 fill-current')
+        <?= __('Lire la suite') ?>
+      </a>
+    </p>
+
+  </header>
+
+</article>
index 9e9ca50d5e85f74ca720a108b07e0dc1e3bcfcf9..eb145003f5ac1b469c5dd881f18b1a75652902fd 100644 (file)
@@ -2,23 +2,27 @@
 
   <header class="mr-2v mb-2v">
 
-    <div class="pb-8">
-      <em>{{ __('Publié par') }}</em>
-      <br/>
-      {{-- Todo: get linked post type data for user from published_by ID --}}
-      <strong>{{ tr_posts_field('published_by') }}</strong>
-    </div>
-
-    @foreach(tr_posts_field('images') as $image)
-      <div class="post-featured-image mb-4" style="background-image: url({{ wp_get_attachment_image_url($image, 'full') }})">
-        <div class="post-featured-image-sizer">{{-- Just here as a proportional sizer thanks to the padding --}}</div>
+
+    @if ($published_by)
+      <div class="pb-8 text-center">
+        <div class="mx-auto rounded-full bg-light bg-cover bg-center mb-2"
+             style="background-image: url({{ wp_get_attachment_image_url($published_by['photo'], 'medium') }}); max-width: 135px">
+          <div class="pb-100%">{{-- Image sizer to make square --}}</div>
+        </div>
+        <em>{{ __('Publié par') }}</em>
+        <br/>
+        <strong>{{ $published_by['name'] }}</strong>
       </div>
+    @endif
+
+    @foreach($images as $image)
+      {!! wp_get_attachment_image($image, 'medium', false, ['class' => 'mb-4']) !!}
     @endforeach
 
   </header>
 
-  <div class="entry-content mb-2v">
-    <h1 class="plain my-4 h2">
+  <div class="entry-content mb-2v" style="flex-basis: 70%">
+    <h1 class="plain mb-4 h2">
       {!! $title !!}
     </h1>
 
index 35e2b2cd3643b3652e97f00d683a0b34a84f250f..f96dafc7e4426b9d007d4c51aeffd43b2565bae4 100644 (file)
@@ -6,7 +6,7 @@
     </a>
   </div>
 
-  <header>
+  <header style="flex-basis: 100%">
     @include('partials/entry-meta')
 
     <h2 class="plain my-4">