https://github.com/aligent/aligent_sociallinks_m2
Magento 2 module to specify links to the social accounts for a particular website.
https://github.com/aligent/aligent_sociallinks_m2
magento2 social-media widget
Last synced: 6 months ago
JSON representation
Magento 2 module to specify links to the social accounts for a particular website.
- Host: GitHub
- URL: https://github.com/aligent/aligent_sociallinks_m2
- Owner: aligent
- License: gpl-3.0
- Created: 2017-07-17T02:08:46.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2022-05-16T23:34:12.000Z (about 4 years ago)
- Last Synced: 2025-02-16T13:23:55.160Z (over 1 year ago)
- Topics: magento2, social-media, widget
- Language: PHP
- Homepage:
- Size: 43 KB
- Stars: 1
- Watchers: 36
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Aligent SocialLinks Magento 2 Module
This module will allow you to specify links to the social accounts for a particular website.
## Installing
Ensure the repository `https://github.com/aligent/Aligent_SocialLinks_M2.git` is listed under the repositories section in your `composer.json` file, e.g.
```
"repositories": [
{
"type": "vcs",
"url": "https://github.com/aligent/Aligent_SocialLinks_M2.git"
}
]
```
Then run
`composer require aligent/sociallinks`
If the latest release isn't included, you may need to edit the `composer.json` file manually, changing the entry to `"aligent/sociallinks": "dev-master"`, and then running `composer update aligent/sociallinks`
## Enable the module
`bin/magento module:enable Aligent_SocialLinks`
An instance of the Widget will be automatically created and assigned to the currently active theme.
## Create Instance of Widget through Upgrade script
The following file contents shows the minimum requirements of the upgrade script to create an instance of the SocialLinks widget and save it to the database
```php
widgetFactory = $widgetFactory;
}
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
if (version_compare($context->getVersion(), '1.0.0', '<')) {
$widgetData = [
'instance_type' => 'Aligent\\SocialLinks\\Block\\SocialLinks',
'title' => 'Aligent Social Links'
];
// Update the usernames for each of the required social networks
// If a network isn't required, it can be removed from the array
$widgetParams = [
'display_text' => 'network_name',
'twitter' => 'aligent',
'facebook' => 'aligent',
'instagram' => 'aligent',
'youtube' => 'aligent',
'snapchat' => 'aligent',
'pinterest' => 'aligent',
'tiktok' => 'aligent',
'linkedin' => 'aligent'
];
$widget = $this->widgetFactory->create();
$widget->addData($widgetData);
$widget->setWidgetParameters($widgetParams);
$widget->setPageGroups(null);
$widget->save();
}
}
}
```
## Adding module to page
The module will then need to be added to a page/s using XML. The following line, place inside a `referenceContainer` will
achieve this
``
## Styling the links
The links aren't styled at all, and will just display the name of the social network inside an tag. This makes it
very straightforward for you to use any styling you would like, along with any icons.
The links are contained in the following HTML structure
```
```
## Using your own custom template
If you would like to overwrite the default template, and display the links in another way, you can do that very easily.
Create a new `social-links.phtml` file in your theme's folder inside `design`, E.g.
`app/design/frontend/Magento/{your_theme_name}/Aligent_SocialLinks/templates/social-links.phtml`
Inside the template `$block` will be an instance of `Aligent\SocialLinks\Block\SocialLinks`, and you simply call
`$block->getUrls()` to get the URLs set in the database