Skip to content

Commit

Permalink
Apply person node styles consistently in lists and teasers
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 11, 2024
1 parent a5a02d8 commit 7eb6087
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Drupal\stanford_decoupled\Plugin\GraphQL\SchemaExtension;

use Drupal\graphql\GraphQL\ResolverBuilder;
use Drupal\graphql\GraphQL\ResolverRegistryInterface;
use Drupal\graphql_compose\Plugin\GraphQL\SchemaExtension\ResolverOnlySchemaExtensionPluginBase;
use Drupal\stanford_publication\Entity\CitationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Layout Schema Extension.
*
* @codeCoverageIgnore
*
* @SchemaExtension(
* id = "stanford_citation_bibliography",
* name = "Stanford Decoupled Bibliography",
* description = @Translation("Layout entities"),
* schema = "graphql_compose",
* )
*/
class CitationSchemaExtension extends ResolverOnlySchemaExtensionPluginBase {

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create(
$container,
$configuration,
$plugin_id,
$plugin_definition
);
return $instance;
}

/**
* {@inheritdoc}
*/
public function registerResolvers(ResolverRegistryInterface $registry): void {
$builder = new ResolverBuilder();

$registry->addFieldResolver('CitationInterface', 'apa',
$builder->callback(fn(CitationInterface $citation) => $citation->getBibliography()),
);
$registry->addFieldResolver('CitationInterface', 'chicago',
$builder->callback(fn(CitationInterface $citation) => $citation->getBibliography(CitationInterface::CHICAGO)),
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
* {@inheritdoc}
*
* @GraphQLComposeEntityType(
* id = "citation"
* id = "citation",
* prefix = "Citation",
* base_fields = {
* "created" = {},
* "changed" = {},
* "title" = {
* "field_type" = "entity_label",
* }
* },
* )
*/
class Citation extends GraphQLComposeEntityTypeBase {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Drupal\stanford_decoupled\Plugin\GraphQLCompose\SchemaType;

use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeSchemaTypeBase;
use GraphQL\Type\Definition\CustomScalarType;
use GraphQL\Type\Definition\ObjectType;
use function Symfony\Component\String\u;

/**
* {@inheritDoc}
*
* @codeCoverageIgnore
*
* @GraphQLComposeSchemaType(
* id = "Bibliography"
* )
*/
class Bibliography extends GraphQLComposeSchemaTypeBase {

/**
* {@inheritdoc}
*/
public function getTypes(): array {
$types = [];

$types[] = new CustomScalarType([
'name' => $this->getPluginId(),
'description' => (string) $this->t('Bibliography citation format markup.'),
]);

return $types;
}

/**
* {@inheritDoc}
*/
public function getExtensions(): array {
$extensions = parent::getExtensions();
$citation_types = $this->entityTypeManager->getStorage('citation_type')
->loadMultiple();
foreach (array_keys($citation_types) as $citation_type) {
$citation_type = u($citation_type)
->camel()
->title()
->toString();

$extensions[] = new ObjectType([
'name' => 'Citation' . trim($citation_type, 's'),
'fields' => fn() => [
'apa' => static::type('Bibliography'),
'chicago' => static::type('Bibliography'),
],
]);
}

return $extensions;
}

}

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,7 @@
@include modular-spacing('margin-bottom', 4);
}

// Make the people referenced entity pictures circles.
.su-person-photo {
@include margin(0 auto);
@include padding(30px);
max-width: 300px;

picture,
img {
border-radius: 50%;
}
}

.ds-entity--stanford-person {
text-align: center;

h3 {
font-size: 1.4em;
margin-bottom: 1.0rem;
}
}

.su-list-unstyled {
li {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@charset 'UTF-8';
@import '../../config';

// Make the people referenced entity pictures circles.
.su-person-photo {
@include margin(0 auto);
@include padding(30px);
max-width: 300px;

picture,
img {
border-radius: 50%;
}
}

.ds-entity--stanford-person {
text-align: center;

a {
color: $su-color-bright-red;

&:active,
&:focus,
&:hover {
color: $su-color-black;
text-decoration: underline;
}
}

h3 {
font-size: 1.4em;
margin-bottom: 1.0rem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ function stanford_profile_styles_field_widget_smartdate_timezone_form_alter(arra
* Implements hook_entity_display_build_alter().
*/
function stanford_profile_styles_entity_display_build_alter(&$build, $context) {
if ($context['entity']->getEntityTypeId() == 'node') {
$bundle = $context['entity']->bundle();
// Add libraries that correspond to the current paragraph type. No need to
// check for the existing library. No message is created if no library exists.
$build['#attached']['library'][] = "stanford_profile_styles/node.$bundle";
}

if ($context['entity']->getEntityTypeId() != 'paragraph') {
return;
}
Expand Down

0 comments on commit 7eb6087

Please sign in to comment.